Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is std::tie not marked constexpr for C++14?

This is a follow-up question to my previous questions "Which parts of the C++14 Standard Library could be and which parts will be made constexpr?" and "Guidelines to do constexpr operator-overloading?"

In the runtime world, a nice idiom to overload operator< for a struct of several data members, is to use std::tie to convert a struct into a std::tuple and piggy-back on its operator< which does the Right Thing™ (lexicographic comparison on the various members).

In C++14, many parts of std::tuple are made constexpr, in particular make_tuple, std::get and the earlier mentioned operator<. However, it appears that the seemingly related std::tie is not marked constexpr. This is rather annoying because it makes defining user-defined literal types that can be compared at compile-time more verbose than necessary.

Question: are there any technical reasons for which std::tie is not marked constexpr for C++14?

UPDATE: LWG issue 2301, implemented in libc++ and libstdc++ bug 65978

UPDATE2: fixed by @JonathanWakely a little over 3 hours after submitting the libstdc++ bug report!

like image 973
TemplateRex Avatar asked Sep 10 '13 19:09

TemplateRex


1 Answers

In any case where it would utilize constexprness, make_tuple should behave exactly the same as tie except that notionally tie would add an extra level of unneeded indirection from the references. Thus there's no need for tie to be constexpr since make_tuple would serve that purpose.

like image 160
Mark B Avatar answered Oct 31 '22 17:10

Mark B