Namespaces
Variants
Views
Actions

std::experimental::ranges::Constructible

From cppreference.com
< cpp‎ | experimental‎ | ranges
template < class T, class... Args >

concept bool __ConstructibleObject =  /* exposition only */
    Destructible<T>() && requires(Args&&... args) {
       T{ std::forward<Args>(args)... };
       new T{ std::forward<Args>(args)... };
    };

template < class T, class... Args >
concept bool __BindableReference = /* exposition only */
    std::is_reference<T>::value && requires(Args&&... args) {
       T( std::forward<Args>(args)... );
    };

template < class T, class... Args >
concept bool Constructible() {
    return __ConstructibleObject<T, Args...> || __BindableReference<T, Args...>;

}
(ranges TS)

The concept Constructible<T, Args..>() is used to constrain a type to be either an object type constructible from a set of types, or a reference type that can be bound to those arguments.

[edit] Notes

As of the current working draft, Constructible<int&, char&>() is satisfied because the cast in __BindableReference is a reinterpret_cast.

Unlike std::is_constructible, Constructible requires a new-expression to be valid and also uses list-initialization, where narrowing conversions are not allowed, initializer-list constructors are preferentially called, and aggregate initialization can be performed. For example:

  • Constructible<int, double>() is not satisfied, even though ConvertibleTo<double, int>() is satisfied and std::is_constructible<int, double>::value is true.
  • Given struct A { int a; };, Constructible<A, int>() is satisfied, even though std::is_constructible<A, int>::value is false.

[edit] See also

checks if a type has a constructor for specific arguments
(class template) [edit]