Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

What is the current status of std::make_array function proposed here? I cannot find any information about its potential acceptance. According to cppreference.com, it's in the std::experimental namespace. It's not mentioned at all on C++ compiler support nor on Wikipedia-C++17, Wikipedia-C++20, and C++17 Standard draft.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
286 views
Welcome To Ask or Share your Answers For Others

1 Answer

As @DeiDei writes, C++17 includes template argument deduction for classes, so you can now write:

std::pair p (foo, bar);
std::array arr = { 1, 2, 3, 4, 5 };

and so on. But there are some (somewhat subtle) remaining use cases where make_pair or make_array can be useful, and you can read about them in: Usefulness of std::make_pair and std::make_tuple in C++1z

@Ruslan correctly notes in a comment that the above is mostly useful when the type of the elements is "obvious" to the compiler, or made explicit for each element. If you want to implicitly construct elements of some type, the above looks like;

std::array arr = { MyType{1,2}, MyType{3,4}, MyType{5,6}, MyType{7,8} };

which is too wordy; and that's one of the cases where you fall back on:

std::make_array<MyType>{ {1,2}, {3,4}, {5,6}, {7,8} };

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...