fork(1) download
  1. #include <iostream>
  2. #include <type_traits>
  3. #include <vector>
  4. using namespace std;
  5. struct bar{
  6.  
  7. };
  8. template<typename T>
  9. void foo(const T &t){
  10. static_assert(std::is_same<typename T::value_type,bar>::value
  11. ,"element type must be bar"
  12. );
  13. }
  14.  
  15. int main() {
  16. // your code goes here
  17.  
  18. foo(std::vector<bar>());
  19. foo(std::vector<int>());
  20.  
  21. return 0;
  22. }
Compilation error #stdin compilation error #stdout 0s 3336KB
stdin
Standard input is empty
compilation info
prog.cpp: In instantiation of ‘void foo(const T&) [with T = std::vector<int>]’:
prog.cpp:19:24:   required from here
prog.cpp:10:2: error: static assertion failed: element type must be bar
  static_assert(std::is_same<typename T::value_type,bar>::value
  ^
stdout
Standard output is empty