Skip to content

Instantly share code, notes, and snippets.

@utilForever
Created February 14, 2017 01:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utilForever/a7684f9a7f0b63aa66408f01c29354c8 to your computer and use it in GitHub Desktop.
Save utilForever/a7684f9a7f0b63aa66408f01c29354c8 to your computer and use it in GitHub Desktop.
std::is_constructible, std::is_trivially_constructible, std::is_nothrow_constructible
#include <iostream>
#include <type_traits>
class Foo {
int v1;
double v2;
public:
Foo(int n) : v1(n), v2() {}
Foo(int n, double f) noexcept : v1(n), v2(f) {}
};
int main() {
std::cout << "Foo is ...\n" << std::boolalpha
<< "\tTrivially-constructible from const Foo&? "
<< std::is_trivially_constructible<Foo, const Foo&>::value << '\n'
<< "\tTrivially-constructible from int? "
<< std::is_trivially_constructible<Foo, int>::value << '\n'
<< "\tConstructible from int? "
<< std::is_constructible<Foo, int>::value << '\n'
<< "\tNothrow-constructible from int? "
<< std::is_nothrow_constructible<Foo, int>::value << '\n'
<< "\tNothrow-constructible from int and double? "
<< std::is_nothrow_constructible<Foo, int, double>::value << '\n';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment