Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Sample Code from Scott Meyer's Blog
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
/** * 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 }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.42 sec, absolute running time: 0.1 sec, cpu time: 0.04 sec, memory peak: 3 Mb, absolute service time: 0,52 sec
edit mode
|
history
|
discussion
il.size() = 0 il.size() = 1 il.size() = 0 il.size() = 1 il.size() = 0 il.size() = 0