Praxeolitic
Praxeolitic

Reputation: 24129

Identify automatically generated member functions

Special member functions are "functions which the compiler will automatically generate if they are used, but not declared explicitly by the programmer".

http://en.wikipedia.org/wiki/Special_member_functions

Details are in §12 of the C++11 Standard:

The default constructor (12.1), copy constructor and copy assignment operator (12.8), move constructor and move assignment operator (12.8), and destructor (12.4) are special member functions. [Note: The implementation will implicitly declare these member functions for some class types when the program does not explicitly declare them. The implementation will implicitly define them if they are odr-used (3.2). See 12.1,12.4 and 12.8. —end note]

What known methods can identify all generated special member functions upon compilation?

My preferred compilers are gcc and clang.

Upvotes: 0

Views: 130

Answers (1)

Rafal Mielniczuk
Rafal Mielniczuk

Reputation: 1342

In c++11, header <type_traits> defines a set of following functions:

is_constructible
is_default_contructible
is_copy_contructible
is_move_contructible
is_assignable
is_copy_assignable
is_move_assignable
is_destructible

You can use them to test for existence of implicitly generated methods at compile time, eg.:

std::is_constructible<ClassName>::value

Upvotes: 1

Related Questions