Consider code below:
#include <iostream>
#include <utility>
#include <tuple>
template <class TargetIndices, class SourceIndices>
struct assign;
template <size_t... TargetIs, size_t... SourceIs>
struct assign<std::index_sequence<TargetIs...>, std::index_sequence<SourceIs...>>: assign<std::index_sequence<TargetIs>, std::index_sequence<SourceIs>>... {
template <class TargetTuple, class SourceTuple>
assign(TargetTuple &target, const SourceTuple &source): assign<std::index_sequence<TargetIs>, std::index_sequence<SourceIs>>(target, source)... { }
};
template <size_t FirstTI, size_t FirstSI>
struct assign<std::index_sequence<FirstTI>, std::index_sequence<FirstSI>> {
template <class TargetTuple, class SourceTuple>
assign(TargetTuple &target, const SourceTuple &source) {
std::get<FirstTI>(target) = std::get<FirstSI>(source);
}
};
int main() {
std::tuple<int, int, int> t1 = std::make_tuple(0,0,0), t2 = std::make_tuple(1,2,3);
assign<std::index_sequence<0,2>, std::index_sequence<2,0>>(t1, t2);
std::cout << std::get<0>(t1) << " " << std::get<1>(t1) << " " << std::get<2>(t1) << std::endl;
}
clang++ states that there is a circular dependency at the inheritance. g++ compiles it without any problems. Which compiler is right?
It looks like a clang bug.
A minimal reproduction looks like this:
template <int...> struct q {};
template <int... Is> using w = q<Is...>;
template <class T>
struct a;
template <int F>
struct a<w<F>> {};
template <int... T>
struct a<w<T...>>: a<w<T>>... {}; // g++ OK, clang++ breaks
The template alias is essential here. When the original template is used in the last line instead of the template alias, it compiles:
struct a<q<T...>>: a<q<T>>... {}; // g++, clang++ OK
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With