Код: Выделить всё
group a{1, 2};
group b{a, 3}; // synonym to group b{1, 2, 3}
Код: Выделить всё
#include
#include
#include
template
struct group;
template
static constexpr inline std::array make_array
(Args &&... args) {
return { args... };
}
template
static constexpr inline auto make_array_i
(auto &&... args_begin, std::index_sequence, const group &v, auto &&... args_end) {
return make_array(args_begin..., v[Indices]..., args_end...);
}
template
static constexpr inline auto make_array
(auto &&... args_begin, const group &v, auto &&... args_end) {
return make_array_i(args_begin..., std::make_index_sequence{}, v, args_end...);
}
template
struct group {
template
constexpr group(Args &&... args) : dat(make_array(args...)) {}
constexpr const Member &operator[](const size_t d) const {
return dat[d];
}
private:
std::array dat;
};
int main() {
group a{1, 2};
// group b{1, a};
}
Я также пробовал заключать аргументы в двойные скобки в первая перегрузка make_array (
Код: Выделить всё
{{ args... }}Я не могу отказаться от std::array и предпочел бы оставить все constexpr. Это взято из более крупного фрагмента кода, отсюда и статические определения методов.
Вот полное сообщение об ошибке для тех, кому интересно:
Код: Выделить всё
min.cpp: In instantiation of ‘constexpr group::group(Args&& ...) [with Args = {int, group&}; Member = int; long unsigned int Dim = 3]’:
min.cpp:41:22: required from here
min.cpp:29:58: error: array must be initialized with a brace-enclosed initializer
29 | constexpr group(Args &&... args) : dat(make_array(args...)) {}
| ~~~~~~~~~~^~~~~~~~~
min.cpp: In instantiation of ‘constexpr group::group(Args&& ...) [with Args = {int&}; Member = int; long unsigned int Dim = 2]’:
min.cpp:11:19: required from ‘constexpr std::array make_array(Args&& ...) [with Args = {int&, group&}; typename std::common_type::type = group]’
min.cpp:29:51: required from ‘constexpr group::group(Args&& ...) [with Args = {int, group&}; Member = int; long unsigned int Dim = 3]’
min.cpp:41:22: required from here
min.cpp:29:58: error: array must be initialized with a brace-enclosed initializer
min.cpp: In instantiation of ‘constexpr group::group(Args&& ...) [with Args = {group&}; Member = int; long unsigned int Dim = 2]’:
min.cpp:11:19: required from ‘constexpr std::array make_array(Args&& ...) [with Args = {int&, group&}; typename std::common_type::type = group]’
min.cpp:29:51: required from ‘constexpr group::group(Args&& ...) [with Args = {int, group&}; Member = int; long unsigned int Dim = 3]’
min.cpp:41:22: required from here
min.cpp:29:58: error: array must be initialized with a brace-enclosed initializer
Подробнее здесь: https://stackoverflow.com/questions/784 ... alized-std
Мобильная версия