Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sample Code from Scott Meyer's Blog
/** * Code example from Scott Meyer's blog entry * "Help me sort out the meaning of '{}' as a constructor argument" * (http://scottmeyers.blogspot.com/2016/11/help-me-sort-out-meaning-of-as.html) */ #include <iostream> #include <initializer_list> class DefCtor { public: DefCtor(){} }; class DeletedDefCtor { public: DeletedDefCtor() = delete; }; class NoDefCtor { public: NoDefCtor(int){} }; template<typename T> class X { public: X() { std::cout << "Def Ctor\n"; } X(std::initializer_list<T> il) { std::cout << "il.size() = " << il.size() << '\n'; } }; int main() { X<DefCtor> a0({}); // il.size = 0 X<DefCtor> b0{{}}; // il.size = 1 X<DeletedDefCtor> a2({}); // il.size = 0 X<DeletedDefCtor> b2{{}}; // il.size = 1 X<NoDefCtor> a1({}); // il.size = 0 X<NoDefCtor> b1{{}}; // il.size = 0 }
run
|
edit
|
history
|
help
0
member function pointer
ADAKOHL - hpclearn
12hours Clock c++
aa
Cley
data locality - slow example
Overland pg. 68
fibonacci
cp.cpp
ignat