简体   繁体   中英

Matching std::index_sequence by default argument

Is the following allowed by template argument deduction or is that an undeduced context?

#include <utility>
#include<tuple>

template<std::size_t... I>
auto make(std::index_sequence<I...> = std::make_index_sequence<2>())
{
    return;
}

int main() {
    make();
}

Compile warning is pretty weird

Default arguments are not part of deduction.

So you cannot do what you want here (that way).

If appropriate, you might do:

template <typename Seq = std::index_sequence<0, 1>>
auto make(Seq = std::make_index_sequence<2>())
{
    /*...*/
}

For what it's worth, this compiles:

template<std::size_t... I>
auto make(std::index_sequence<I...> = std::make_index_sequence<sizeof... (I)>())

but probably doesn't do what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM