1 // { dg-do run { target c++11 } } 2 3 // Test user-defined literals. 4 // Test simple operator declaration and definition. 5 6 #include <cstring> 7 #include <string> 8 #include <complex> 9 #include <cassert> 10 11 long double operator"" _v(long double); 12 std::string operator"" _w(const char16_t*, size_t); 13 unsigned operator"" _w(const char*); 14 15 std::complex<double> 16 operator"" _i(long double y) 17 { return std::complex<double>(0.0L, y); } 18 19 void test1()20test1() 21 { 22 long double x = operator"" _v(1.2L); 23 assert(x == 2.2L); 24 25 std::string s = operator"" _w(u"one", 3); 26 assert(s == "boo"); 27 28 unsigned u = operator"" _w("Hello, World!"); 29 assert(u == 13U); 30 31 std::complex<double> i = operator"" _i(2.0); 32 assert(i == std::complex<double>(0.0, 2.0)); 33 } 34 35 int main()36main() 37 { 38 test1(); 39 } 40 41 long double 42 operator"" _v(long double x) 43 { return x + 1.0L; } 44 45 std::string 46 operator"" _w(const char16_t*, size_t) 47 { return std::string("boo"); } 48 49 unsigned 50 operator"" _w(const char* str) 51 { return strlen(str); } 52