Skip to content
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

Implement Concepts v2 #45

Closed
wants to merge 9 commits into from
Closed

Implement Concepts v2 #45

wants to merge 9 commits into from

Conversation

lackhole
Copy link
Owner

@lackhole lackhole commented Sep 3, 2024

Implement <concepts_v2>

  • Support human-readable error message
  • Compatible with old type_traits-like method

template<typename T, typename U, preview_require(
    (preview::integral<T> || preview::floating_point<T>) && preview::signed_integral<U>
)>
void foo(T, U) {}

foo("Hello, C++", 20);

gcc 11

error: no type named 'valid' in 'struct constraints_not_satisfied<integral<const char*>, at<0, 3>, because<constraints_not_satisfied<integral<const char*>, at<0, 1>, because<std::is_integral<const char*>, is_false> > >, and_, floating_point<const char*>, at<1, 3>, because<constraints_not_satisfied<floating_point<const char*>, at<0, 1>, because<std::is_floating_point<const char*>, is_false> > > >'
/preview/test/concepts_v2.cc:97:6: error: no matching function for call to 'foo(const char [11], int)'
   97 |   foo("hello, C++", 20);
      |   ~~~^~~~~~~~~~~~~~~~~~
/preview/test/concepts_v2.cc:33:6: note: candidate: 'template<class T, class U, typename decltype (preview::resolve_require(((integral<T> || floating_point<T>) && (! signed_integral<U>))))::valid <anonymous> > void foo(T, U)'
   33 | void foo(T, U) {}
      |      ^~~
/preview/test/concepts_v2.cc:33:6: note:   template argument deduction/substitution failed:
In file included from /preview/include/preview/concepts_v2.h:12,
from /preview/test/concepts_v2.cc:4:
/preview/include/preview/__concepts_v2/require.h:53:96: error: no type named 'valid' in 'struct constraints_not_satisfied<integral<const char*>, at<0, 3>, because<constraints_not_satisfied<integral<const char*>, at<0, 1>, because<std::is_integral<const char*>, is_false> > >, and_, floating_point<const char*>, at<1, 3>, because<constraints_not_satisfied<floating_point<const char*>, at<0, 1>, because<std::is_floating_point<const char*>, is_false> > > >'
   53 | #define preview_require(...) typename decltype(preview::resolve_require(__VA_ARGS__))::valid = true
      |                                                                                                ^~~~
/preview/test/concepts_v2.cc:30:34: note: in expansion of macro 'preview_require'
   30 | template<typename T, typename U, preview_require(
      |                                  ^~~~~~~~~~~~~~~

Clang

no type named 'valid' in 'constraints_not_satisfied<integral<const char *>, at<0, 3>, because<constraints_not_satisfied<integral<const char *>, at<0, 1>, because<std::is_integral<const char *>, is_false>>>, and_, floating_point<const char *>, at<1, 3>, because<constraints_not_satisfied<floating_point<const char *>, at<0, 1>, because<std::is_floating_point<const char *>, is_false>>>>'
/preview/test/concepts_v2.cc:97:3: error: no matching function for call to 'foo'
  foo("hello, C++", 20);
  ^~~
/preview/test/concepts_v2.cc:33:6: note: candidate template ignored: substitution failure [with T = const char *, U = int]: no type named 'valid' in 'constraints_not_satisfied<integral<const char *>, at<0, 3>, because<constraints_not_satisfied<integral<const char *>, at<0, 1>, because<std::is_integral<const char *>, is_false>>>, and_, floating_point<const char *>, at<1, 3>, because<constraints_not_satisfied<floating_point<const char *>, at<0, 1>, because<std::is_floating_point<const char *>, is_false>>>>'
void foo(T, U) {}
     ^

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant