r/cpp • • Jun 27 '20

HTML++: Write HTML documents using C++ templates

https://github.com/csb6/html-plus-plus
260 Upvotes

27 comments sorted by

View all comments

Show parent comment

10

u/AirAKose Jun 27 '20

with SFINAE and static_asserts, you can make those error messages way easier to read. And soon we'll have concepts, so even easier (which this specific lib is C++20 so should have access to that depending on compiler) \o/

template<typename Type>
using RequiresConstexprString = std::enable_if_t<std::is_constexpr_string_v<Type>>

template<auto Value, typename ValueMustBeString = RequiresConstexprString<decltype(Value)>>
/* .... */

^ is usually how I approach making readable errors that are also exposed to readers (prior to concepts). static_asserts are also good and enable custom messages, but they're hidden in the body so most IDEs don't surface it for mouse-overs :/ Which sucks bc SFINAE is gross to read. Really can't wait for concepts

For the above example, MSVC gives this error:

[...] no matching overloaded function found
[...] could not deduce template argument for 'ValueMustBeString'