A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://cplusplus.github.io/LWG/issue3423 below:

any_cast should never return a cv-qualified type

This page is a snapshot from the LWG issues list, see the Library Active Issues List for more information and the meaning of New status.

3423. std::any_cast should never return a cv-qualified type

Section: 22.7.5 [any.nonmembers] Status: New Submitter: Casey Carter Opened: 2020-04-02 Last modified: 2020-09-06

Priority: 3

View all other issues in [any.nonmembers].

View all issues with New status.

Discussion:

The return type of the non-pointer overloads of std::any_cast<T> is T. This is silly when T is cv-qualified (and, since merging P1152 "Deprecating volatile" into the working draft, deprecated when T is volatile-qualified). We should strip cv-qualifiers to determine the type returned.

[2020-04-18 Issue Prioritization]

Priority to 3 after reflector discussion.

Proposed resolution:

This wording is relative to N4861.

  1. Modify 22.7.2 [any.synop] as indicated:

    […]
    template<class T>
      remove_cv_t<T> any_cast(const any& operand);
    template<class T>
      remove_cv_t<T> any_cast(any& operand);
    template<class T>
      remove_cv_t<T> any_cast(any&& operand);
    […]
    
  2. Modify 22.7.5 [any.nonmembers] as indicated:

    template<class T>
      remove_cv_t<T> any_cast(const any& operand);
    template<class T>
      remove_cv_t<T> any_cast(any& operand);
    template<class T>
      remove_cv_t<T> any_cast(any&& operand);
    

    -4- Let R be the type remove_cv_t<T>, andU be the type remove_cvref_t<T>.

    -5- Mandates: For the first overload, is_constructible_v< T R, const U&> is true. For the second overload, is_constructible_v< T R, U&> is true. For the third overload, is_constructible_v< T R, U> is true. -6- Returns: For the first and second overload, static_cast< T R>(*any_cast<U>(&operand)). For the third overload, static_cast< T R>(std::move(*any_cast<U>(&operand))). -7- Throws: bad_any_cast if operand.type() != typeid(remove_reference_t<T>).

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4