Live data from Hacker News

Enum class improvements for C++17, C++20 and C++23

cppstories.com

1–10 of 121 posts

Re: Enum class improvements for C++17, C++20 and C++23

#4
Speaking of enums, what's a better serialization framework for C++ like Serde in Rust, and then what about Linked Data support and of course also form validation.

Linked Data triples have (subject, predicate, object) and quads have (graph, subject, predicate, object).

RDF has URIs for all Subjects and Predicates.

RDF Objects may be URIs or literal values like xsd:string, xsd:float64, xsd:int (32bit signed value), xsd:integer, xsd:long, xsd:time, xsd:dateTime, xsd:duration.

RDFS then defines Classes and Properties, identified by string URIs.

How best to get from an Enum with (type,attr, {range of values}) to an rdfs:range definition in a schema with a URI prefix?

Python has dataclasses which is newer than attrs, but serde also emits Python pickles

Re: Enum class improvements for C++17, C++20 and C++23

#5

Speaking of enums, what's a better serialization framework for C++ like Serde in Rust, and then what about Linked Data support and of course also form validation. Linked Data triples have (subject, predicate, object) and quads have (graph, subject, predicate, object). RDF has URIs for all Subjects and Predicates. RDF Objects may be URIs or literal values like xsd:string, xsd:float64, xsd:int (32bit signed value), xsd…

re Serde: If you want JSON, https://github.com/beached/daw_json_link is about as close as we can get. It interop's well with the reflection(or like) libraries such as Boost Describe or Boost PFR and will work well with std reflection when it is available.

Re: Enum class improvements for C++17, C++20 and C++23

#7
Odd that it says

  auto value = std::to_underlying(p); // C++23
is "more expressive" than

  uint8_t value = static_cast(Permissions::Read);
The latter seems clearly more expressive, not less. You could tighten it up a bit by using auto on the LHS instead of the redundant uint8_t. In the former I don't know what's going on and I have to go read another header to figure out the type of `value`.

Re: Enum class improvements for C++17, C++20 and C++23

#8

Speaking of enums, what's a better serialization framework for C++ like Serde in Rust, and then what about Linked Data support and of course also form validation. Linked Data triples have (subject, predicate, object) and quads have (graph, subject, predicate, object). RDF has URIs for all Subjects and Predicates. RDF Objects may be URIs or literal values like xsd:string, xsd:float64, xsd:int (32bit signed value), xsd…

So far, most people would use whatever is provided alongside the frameworks they are already using for their application.

Since the 90's, Turbo Vision, OWL, MFC, CSet++, Tools.h++, VCL, ATL, PowerPlant, Qt, Boost, JUCE, Unreal, CryEngine,....

Maybe if reflection does indeed land into C++26, something might be more universally adopted.

Re: Enum class improvements for C++17, C++20 and C++23

#9

    enum class Handle : uint32_t { Invalid = 0 }; 
    Handle h { 42 }; // OK
One of their examples demonstrates the number one issue for me with enums, which was not fixed with `enum class`. Since values outside the range of the type are valid, you are constantly needing to check for invalid values in any function that takes an enum [class]. Ruins any attempt at "parse, don't validate" style in c++ and completely ruins the "type safety" which c++ people are always going on about.

Re: Enum class improvements for C++17, C++20 and C++23

#10
post #7

Odd that it says auto value = std::to_underlying(p); // C++23 is "more expressive" than uint8_t value = static_cast (Permissions::Read); The latter seems clearly more expressive, not less. You could tighten it up a bit by using auto on the LHS instead of the redundant uint8_t. In the former I don't know what's going on and I have to go read another header to figure out the type of `value`.

The expressibility of a language is what can be expressed in it, not what it can express to you. This additional feature allows you to express this projection without being explicit.
Post reply on HN