Make std::invoke and std::reference_wrapper constexpr

253 views
Skip to first unread message

benni...@gmail.com

unread,
Sep 27, 2016, 7:02:06 AM9/27/16
to ISO C++ Standard - Future Proposals
I want to add constexpr to the following functions:

20.14.3 Function template invoke [func.invoke]

template <class F, class... Args>
  constexpr result_of_t<F&&(Args&&...)> invoke(F&& f, Args&&... args);


20.14.4 Class template reference_wrapper [refwrap]

namespace std {
  template <class T> class reference_wrapper {
  public :
    // types
    using type = T;

    // construct/copy/destroy
    constexpr reference_wrapper(T&) noexcept;
    reference_wrapper(T&&) = delete; // do not bind to temporary objects
    constexpr reference_wrapper(const reference_wrapper& x) noexcept;

    // assignment
    constexpr reference_wrapper& operator=(const reference_wrapper& x) noexcept;

    // access
    constexpr operator T& () const noexcept;
    constexpr T& get() const noexcept;

    // invocation
    template <class... ArgTypes>
    constexpr result_of_t<T&(ArgTypes&&...)>
    operator() (ArgTypes&&...) const;
  };
}


20.14.4.5 reference_wrapper helper functions [refwrap.helpers]

template <class T> constexpr reference_wrapper<T> ref(T& t) noexcept;

template <class T> constexpr reference_wrapper<T> ref(reference_wrapper<T> t) noexcept;

template <class T> constexpr reference_wrapper<const T> cref(const T& t) noexcept;

template <class T> constexpr reference_wrapper<const T> cref(reference_wrapper<T> t) noexcept;


invoke and reference_wrapper are very basic and powerful tools that might be used in constexpr functions. I'm working with C++17 for a while and need to implement constexpr versions by my self to use them in constexpr expressions.

Richard Smith

unread,
Sep 27, 2016, 4:48:14 PM9/27/16
to std-pr...@isocpp.org
Yes please :)

--
You received this message because you are subscribed to the Google Groups "ISO C++ Standard - Future Proposals" group.
To unsubscribe from this group and stop receiving emails from it, send an email to std-proposals+unsubscribe@isocpp.org.
To post to this group, send email to std-pr...@isocpp.org.
To view this discussion on the web visit https://groups.google.com/a/isocpp.org/d/msgid/std-proposals/6f3821f7-2f31-47c4-a5eb-56039332b537%40isocpp.org.

benni...@gmail.com

unread,
Sep 28, 2016, 10:49:56 AM9/28/16
to ISO C++ Standard - Future Proposals

benni...@gmail.com

unread,
Sep 28, 2016, 12:08:22 PM9/28/16
to ISO C++ Standard - Future Proposals, benni...@gmail.com

Tomasz

unread,
Sep 29, 2016, 12:50:09 AM9/29/16
to ISO C++ Standard - Future Proposals, benni...@gmail.com


W dniu wtorek, 27 września 2016 13:02:06 UTC+2 użytkownik benni...@gmail.com napisał:
I want to add constexpr to the following functions:

The problem you need to discuss is that per current resolution of the http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1581 adding constexpr to the invoke and other functional components, would break existing code. The actual examples may be found at:
https://llvm.org/bugs/show_bug.cgi?id=23141
https://llvm.org/bugs/show_bug.cgi?id=23135
I believe you paper need to discuss the scope of the issues and propose some resolutions workarounds.

benni...@gmail.com

unread,
Sep 29, 2016, 6:00:19 AM9/29/16
to ISO C++ Standard - Future Proposals, benni...@gmail.com
Hi Tomasz,

thank you very much for the links, I will try to write a discussion about that. Interesting to learn that constexpr can break existing code. Any help is welcome of course. :-)
Reply all
Reply to author
Forward
0 new messages