##### cppreference.com

##### Search

Create account

##### Namespaces

- Page
- Discussion

##### Variants

##### Views

- View
- Edit
- History

##### Actions

# std::is_constructible, std::is_trivially_constructible, std::is_nothrow_constructible

From cppreference.com
< cpp‎ | types

Defined in header `<type_traits>` |  |
template< class T, class... Args > struct is_constructible; | (1) | (since C++11)
template< class T, class... Args > struct is_trivially_constructible; | (2) | (since C++11)
template< class T, class... Args > struct is_nothrow_constructible; | (3) | (since C++11)

1) If the expression T obj(arg1, arg2, ... argN); is well-formed, given declval<Args>()... as arguments, provides the member constant `value` equal true. For any other type, `value` is false.

2) same as 1), but the constructor expression does not call any operation that is not trivial.

3) same as 1), but the constructor expression is noexcept.

## Inherited from std::integral_constant

### Member constants

value [static] | true if `T` is constructible from `Args...` , false otherwise (public static member constant)

### Member functions

operator bool | converts the object to bool, returns `value` (public member function)

### Member types

Type | Definition
`value_type` | `bool`
`type` | std::integral_constant<bool, value>

### [edit] Example

Run this code

    #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';
    }

Output:

    Foo is ...
            Trivially-constructible from const Foo&? true
            Trivially-constructible from int? false
            Constructible from int? true
            Nothrow-constructible from int? false
            Nothrow-constructible from int and double? true

### [edit] See also

is_default_constructible is_trivially_default_constructible is_nothrow_default_constructible (C++11)(C++11)(C++11) | checks if a type has a default constructor (class template) [edit]
is_copy_constructible is_trivially_copy_constructible is_nothrow_copy_constructible (C++11)(C++11)(C++11) | checks if a type has a copy constructor (class template) [edit]
is_move_constructible is_trivially_move_constructible is_nothrow_move_constructible (C++11)(C++11)(C++11) | checks if a type has a move constructor (class template) [edit]
uses_allocator (C++11) | checks if the specified type supports uses-allocator construction (class template) [edit]

Retrieved from "http://en.cppreference.com/mwiki/index.php?title=cpp/types/is_constructible&oldid=70573"