Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- std::vector<int> v;
- v.emplace_back(1);
- v.emplace_back({1});
- v.emplace_back(int{1});
- v.emplace_back({1});
- #include <iostream>
- #include <initializer_list>
- struct A
- {
- template <typename ...T>
- void f( T &&... ) const {}
- };
- int main()
- {
- A().f( { 1 } );
- return 0;
- }
- prog.cpp: In function 'int main()':
- prog.cpp:13:15: error: no matching function for call to 'A::f(<brace-enclosed initializer list>)'
- A().f( { 1 } );
- ^
- prog.cpp:8:7: note: candidate: void A::f(T&& ...) const [with T = {}]
- void f( T &&... ) const {}
- ^
- prog.cpp:8:7: note: candidate expects 0 arguments, 1 provided
- #include <iostream>
- #include <initializer_list>
- struct A
- {
- template <typename ...T>
- void f( T &&... ) const {}
- };
- int main()
- {
- A().f<int>( { 1 } );
- return 0;
- }
- #include <iostream>
- #include <vector>
- #include <initializer_list>
- int main()
- {
- std::vector<int> v;
- v.emplace_back<int>( { 1 } );
- for ( int x : v ) std::cout << x << ' ';
- std::cout << std::endl;
- return 0;
- }
- 1
- #include <iostream>
- #include <vector>
- struct S
- {
- S(std::initializer_list<int>) {}
- };
- int main()
- {
- std::vector<S> v;
- v.emplace_back<std::initializer_list<int>>({1});
- }
- v.emplace_back(int{1});
Add Comment
Please, Sign In to add comment