Guest User

Untitled

a guest
Nov 25th, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. std::vector<int> v;
  2. v.emplace_back(1);
  3. v.emplace_back({1});
  4. v.emplace_back(int{1});
  5.  
  6. v.emplace_back({1});
  7.  
  8. #include <iostream>
  9. #include <initializer_list>
  10.  
  11. struct A
  12. {
  13. template <typename ...T>
  14. void f( T &&... ) const {}
  15. };
  16.  
  17. int main()
  18. {
  19. A().f( { 1 } );
  20.  
  21. return 0;
  22. }
  23.  
  24. prog.cpp: In function 'int main()':
  25. prog.cpp:13:15: error: no matching function for call to 'A::f(<brace-enclosed initializer list>)'
  26. A().f( { 1 } );
  27. ^
  28. prog.cpp:8:7: note: candidate: void A::f(T&& ...) const [with T = {}]
  29. void f( T &&... ) const {}
  30. ^
  31. prog.cpp:8:7: note: candidate expects 0 arguments, 1 provided
  32.  
  33. #include <iostream>
  34. #include <initializer_list>
  35.  
  36. struct A
  37. {
  38. template <typename ...T>
  39. void f( T &&... ) const {}
  40. };
  41.  
  42. int main()
  43. {
  44. A().f<int>( { 1 } );
  45.  
  46. return 0;
  47. }
  48.  
  49. #include <iostream>
  50. #include <vector>
  51. #include <initializer_list>
  52.  
  53. int main()
  54. {
  55. std::vector<int> v;
  56.  
  57. v.emplace_back<int>( { 1 } );
  58.  
  59. for ( int x : v ) std::cout << x << ' ';
  60. std::cout << std::endl;
  61.  
  62. return 0;
  63. }
  64.  
  65. 1
  66.  
  67. #include <iostream>
  68. #include <vector>
  69.  
  70. struct S
  71. {
  72. S(std::initializer_list<int>) {}
  73. };
  74.  
  75. int main()
  76. {
  77. std::vector<S> v;
  78. v.emplace_back<std::initializer_list<int>>({1});
  79. }
  80.  
  81. v.emplace_back(int{1});
Add Comment
Please, Sign In to add comment