fork download
  1. #include <string>
  2. #include <vector>
  3. #include <type_traits>
  4.  
  5. template<typename StringT, typename Container = std::vector<StringT>>
  6. auto split(StringT&& toSplit, StringT&& delim)
  7. ->std::enable_if_t < std::is_same<StringT, typename Container::value_type>{}() >{}
  8.  
  9. int main(){
  10. split<std::string>("hello world", " ");
  11. split<std::string, std::vector<double>("hello world", " ");
  12. }
Compilation error #stdin compilation error #stdout 0s 15240KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:11:59: error: temporary of non-literal type ‘std::vector<double>’ in a constant expression
  split<std::string, std::vector<double>("hello world", " ");
                                                           ^
In file included from /usr/include/c++/6/vector:64:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/stl_vector.h:214:11: note: ‘std::vector<double>’ is not literal because:
     class vector : protected _Vector_base<_Tp, _Alloc>
           ^~~~~~
/usr/include/c++/6/bits/stl_vector.h:214:11: note:   ‘std::vector<double>’ has a non-trivial destructor
prog.cpp:11:2: error: parse error in template argument list
  split<std::string, std::vector<double>("hello world", " ");
  ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
prog.cpp:11:2: error: statement cannot resolve address of overloaded function
stdout
Standard output is empty