Namespaces
Variants
Views
Actions

std::experimental::ranges::Constructible

From cppreference.com
< cpp‎ | experimental‎ | ranges
 
 
Technical specifications
Filesystem library (filesystem TS)
Library fundamentals (library fundamentals TS)
Library fundamentals 2 (library fundamentals 2 TS)
Extensions for parallelism (parallelism TS)
Extensions for concurrency (concurrency TS)
Concepts (concepts TS)
Ranges (ranges TS)
Special mathematical functions (special math TR)
 
 
Concepts library
Core language concepts
                              
Object concepts
                              
                              
Comparison concepts
Callable concepts
                                        
                              
URNG concept
 
template < class T, class... Args >

concept bool __ConstructibleObject =  /* exposition only */
    ranges::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]