Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

is_swappable type traits should not be in namespace std #259

Closed
ericniebler opened this issue Nov 11, 2016 · 1 comment
Closed

is_swappable type traits should not be in namespace std #259

ericniebler opened this issue Nov 11, 2016 · 1 comment

Comments

@ericniebler
Copy link
Owner

ericniebler commented Nov 11, 2016

They are defined in terms of unqualified calls to swap, but swap is unconstrained in C++14. Solution: move the swappable traits into the std::experimental::ranges namespace and define them in terms of the ranges::swap customization point object.

@ericniebler
Copy link
Owner Author

ericniebler commented Jan 23, 2017

Proposed wording

To Table 1 -- Ranges TS library headers, add <experimental/ranges/type_traits>.

From the <type_traits> synopsis ([meta.type.synop]), remove the declarations of:

  • is_swappable
  • is_swappable_with
  • is_nothrow_swappable
  • is_nothrow_swappable_with
  • is_swappable_v
  • is_swappable_with_v
  • is_nothrow_swappable_v
  • is_nothrow_swappable_with_v

Remove subsection "Type properties" ([meta.unary.prop]).

After subsection "Other transformations" ([meta.trans.other]), add a new subsection "Header <experimental/ranges/type_traits> synopsis" ([meta.type.synop.rng]) with the following:

namespace std { namespace experimental { namespace ranges { inline namespace v1 {
// (REF), type properties:
template <class T, class U> struct is_swappable_with;
template <class T> struct is_swappable;

template <class T, class U> struct is_nothrow_swappable_with;
template <class T> struct is_nothrow_swappable;

template <class T, class U> constexpr bool is_swappable_with_v
    = is_swappable_with<T, U>::value;
template <class T> constexpr bool is_swappable_v
    = is_swappable<T>::value;

template <class T, class U> constexpr bool is_nothrow_swappable_with_v
    = is_nothrow_swappable_with<T, U>::value;
template <class T> constexpr bool is_nothrow_swappable_v
    = is_nothrow_swappable<T>::value;
}}}}

After subsection "Header <experimental/ranges/type_traits> synopsis" ([meta.type.synop.rng]), add a new subsection "Additional type properties" ([meta.unary.prop.rng]) with the following:

[Editor's note: Taken from latest C++17 working draft.]

  1. These templates provide access to some of the more important properties of types.
  2. It is unspecified whether the library defines any full or partial specializations of any of these templates.
  3. For all of the class templates X declared in this subclause, instantiating that template with a template argument that is a class template specialization may result in the implicit instantiation of the template argument if and only if the semantics of X require that the argument must be a complete type.
  4. For the purpose of defining the templates in this subclause, a function call expression declval<T>() for any type T is considered to be a trivial (3.9, 12) function call that is not an odr-use (3.2) of declval in the context of the corresponding definition notwithstanding the restrictions of 20.2.7.

Table XX - Additional type property predicates

Template Condition Precondition
template <class T, class U>
struct is_swappable_with;
The expressions ranges::swap(declval<T>(), declval<U>()) and ranges::swap(declval<U>(), declval<T>()) are each well-formed when treated as an unevaluated operand (Clause 5) in an overload-resolution context for swappable values (17.5.3.2). Access checking is performed as if in a context unrelated to T and U. Only the validity of the immediate context of the swap expressions is considered. [ Note: The compilation of the expressions can result in side effects such as the instantiation of class template specializations and function template specializations, the generation of implicitly-defined functions, and so on. Such side effects are not in the "immediate context" and can result in the program being ill-formed. --end note ] T and U shall be complete types, cv void, or arrays of unknown bound.
template <class T>
struct is_swappable;
For a referenceable type T, the same result as is_swappable_with_v<T&, T&>, otherwise false. T shall be a complete type, cv void, or an array of unknown bound.
template <class T, class U>
struct is_nothrow_swappable_with;
is_swappable_with_v<T, U> is true and each swap expression of the definition of is_swappable_with<T, U> is known not to throw any exceptions (5.3.7). T and U shall be complete types, cv void, or arrays of unknown bound.
template <class T>
struct is_nothrow_swappable;
For a referenceable type T, the same result as is_nothrow_swappable_with_v<T&, T&>, otherwise false. T shall be a complete type, cv void, or an array of unknown bound.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants