From 99c1f88e7396ee87a812f8d114aac8d903eb7afb Mon Sep 17 00:00:00 2001 From: Johannes Stoelp Date: Wed, 28 Sep 2022 22:10:29 +0200 Subject: c++: pre c++20 concept example --- src/development/c++/concepts-11.cc | 53 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 src/development/c++/concepts-11.cc (limited to 'src/development/c++') diff --git a/src/development/c++/concepts-11.cc b/src/development/c++/concepts-11.cc new file mode 100644 index 0000000..888ff4d --- /dev/null +++ b/src/development/c++/concepts-11.cc @@ -0,0 +1,53 @@ +// Copyright (C) 2022 johannst +#include + +template class Checker, typename = void> +struct is_valid : std::false_type {}; + +template class Checker> +struct is_valid>> : std::true_type {}; + +template class Checker> +static constexpr bool is_valid_v = is_valid::value; + +// ----------------------------------------------------------------------------- + +template class Checker, typename = void> +struct is_valid_with_ret : std::false_type {}; + +template class Checker> +struct is_valid_with_ret>> : std::is_same> {}; + +template class Checker> +static constexpr bool is_valid_with_ret_v = is_valid_with_ret::value; + +// ----------------------------------------------------------------------------- + +template +struct is_entry { + template + using init = decltype(std::declval().init()); + template + using tag = decltype(std::declval().tag()); + template + using val = decltype(std::declval().val()); + + static constexpr bool value = is_valid_v && + is_valid_with_ret_v && + is_valid_with_ret_v; +}; + +template +static constexpr bool is_entry_v = is_entry::value; + +template +struct Entry { + using Type = E; + void init(); + int tag() const; + E val() const; +}; + +int main() { + static_assert(is_entry_v>, ""); +} -- cgit v1.2.3