Run Code  | API  | Code Wall  | Misc  | Feedback  | Login  | Theme  | Privacy  | Patreon 

Trigger static_assert even when function signature is invalid

Language: Layout:
+ ] Compiler args + ] Show input
Compilation time: 0.12 sec, absolute service time: 0,21 sec 
edit mode |  history
Error(s):
source_file.cpp:22:3: error: static_assert failed "the template parameter to f should be `foo` or `bar`"
  static_assert(std::is_base_of<compatible_with_f, U>::value,
  ^             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
source_file.cpp:32:3: note: in instantiation of function template specialization 'f<int, int>' requested here
  f<int>(0); // error: no matching function for call to 'f'
  ^
source_file.cpp:24:3: error: no matching function for call to 'f_impl'
  f_impl<U>(std::forward<T>(t));
  ^~~~~~~~~
source_file.cpp:15:6: note: candidate template ignored: substitution failure [with T = int]: type 'int' cannot be used prior to '::' because it has no members
void f_impl(typename T::some_type param) {
     ^               ~
2 errors generated.

        

    
                
λ
.NET NoSQL database for rapid development