Skip to content

Use C++20 for programs that generate the HTML lists #445

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use C++20 default comparisons for section objects
  • Loading branch information
jwakely committed May 29, 2025
commit 95c70dde1891524554da88d1b88b417cecb66bd0
26 changes: 2 additions & 24 deletions src/section_data.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ struct section_num
{
std::string prefix;
std::vector<int> num;

auto operator<=>(const section_num&) const = default;
};

std::istream&
Expand Down Expand Up @@ -82,30 +84,6 @@ operator << (std::ostream& os, const section_num& sn)
return os;
}

bool
operator<(const section_num& x, const section_num& y)
{
if (x.prefix < y.prefix)
return true;
else if (y.prefix < x.prefix)
return false;
return x.num < y.num;
}

bool
operator==(const section_num& x, const section_num& y)
{
if (x.prefix != y.prefix)
return false;
return x.num == y.num;
}

bool
operator!=(const section_num& x, const section_num& y)
{
return !(x == y);
}

typedef std::string section_tag;

std::string
Expand Down
31 changes: 0 additions & 31 deletions src/sections.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,6 @@
#include <cctype>
#include <utility>

auto lwg::operator<(section_tag const & x, section_tag const & y) noexcept -> bool {
return (x.prefix < y.prefix) ? true
: (y.prefix < x.prefix) ? false
: x.name < y.name;
}

auto lwg::operator==(section_tag const & x, section_tag const & y) noexcept -> bool {
return x.prefix == y.prefix && x.name == y.name;
}

auto lwg::operator!=(section_tag const & x, section_tag const & y) noexcept -> bool {
return !(x == y);
}

auto lwg::operator << (std::ostream& os, section_tag const & tag) -> std::ostream & {
os << '[';
if (!tag.prefix.empty()) { os << tag.prefix << "::"; }
Expand All @@ -34,23 +20,6 @@ std::string lwg::as_string(section_tag const & x)
: x.prefix + "::" + x.name;
}

auto lwg::operator < (section_num const & x, section_num const & y) noexcept -> bool {
// prefixes are unique, so there should be no need for a tiebreak.
return (x.prefix < y.prefix) ? true
: (y.prefix < x.prefix) ? false
: x.num < y.num;
}

auto lwg::operator == (section_num const & x, section_num const & y) noexcept -> bool {
return (x.prefix != y.prefix)
? false
: x.num == y.num;
}

auto lwg::operator != (section_num const & x, section_num const & y) noexcept -> bool {
return !(x == y);
}

auto lwg::operator >> (std::istream& is, section_num& sn) -> std::istream & {
sn.prefix.clear();
sn.num.clear();
Expand Down
15 changes: 2 additions & 13 deletions src/sections.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,33 +13,22 @@ struct section_tag
{
std::string prefix; // example: fund.ts.v2
std::string name; // example: meta.logical
auto operator<=>(const section_tag&) const = default;
};

struct section_num {
std::string prefix; // example: fund.ts.v2
std::vector<int> num; // sequence of numbers corresponding to section number
// in relevant doc, e.g,, 17.5.2.1.4.2
auto operator<=>(const section_num&) const = default;
};

using section_map = std::map<section_tag, section_num>;

auto operator < (section_tag const & x, section_tag const & y) noexcept -> bool;
auto operator == (section_tag const & x, section_tag const & y) noexcept -> bool;
auto operator != (section_tag const & x, section_tag const & y) noexcept -> bool;
auto operator << (std::ostream & os,
section_tag const & tag) -> std::ostream &; // with square brackets
std::string as_string(section_tag const & x); // without square brackets

auto operator < (section_num const & x, section_num const & y) noexcept -> bool;
// section 'x' sorts before section 'y' if its 'prefix' field lexicographically
// precedes that of 'y', and its 'nun' field lexicographically precedes that
// of 'y' if the prefix fields are equivalent.

auto operator == (section_num const & x, section_num const & y) noexcept -> bool;
auto operator != (section_num const & x, section_num const & y) noexcept -> bool;
// Two 'section_num' objects compare equal if their 'prefix' and 'num' both
// compare equal.

auto operator >> (std::istream & is, section_num & sn) -> std::istream &;
auto operator << (std::ostream & os, section_num const & sn) -> std::ostream &;

Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy