-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't construct tuple<T, U> passing (const T&, const U&) in the constructor #28
Comments
Further investigation have shown that while std::tuples are constructed from multiple arguments without problem Modified example: https://godbolt.org/z/sdsPevGaq #include <iostream>
#ifdef USE_STD_TUPLE
#include <tuple>
using std::apply;
using std::tie;
using std::tuple;
#define WRAP_TUPLE_ARGS(...) __VA_ARGS__
#else
#include "https://raw.githubusercontent.com/codeinred/tuplet/main/include/tuplet/tuple.hpp"
using tuplet::apply;
using tuplet::tie;
using tuplet::tuple;
#define WRAP_TUPLE_ARGS(...) { __VA_ARGS__ }
#endif
template <typename... DepValues>
class Foo {
public:
Foo(const DepValues&... deps) : m_deps(WRAP_TUPLE_ARGS(deps...)) {}
void dump() { apply(Foo::dumpValues<DepValues...>, this->m_deps); }
private:
template <typename... Values>
static void dumpValues(const Values&... values) {
(Foo::dumpOne(values), ...);
};
template <class Value>
static void dumpOne(const Value& value) {
std::cout << value << ", ";
}
using dep_holder_t = tuple<DepValues...>;
dep_holder_t m_deps;
};
int main() {
using T = Foo<int, int>;
T t{3, 5};
t.dump();
} |
clang-12 warns on braces https://godbolt.org/z/rYTTPxcTT
and I have no idea how to change code to satisfy it. Also I found another difference: If we have tuple of template wrappers that accept single argument, then std::tuple can automatically construct it, while tuplet can't. It hard to explain, just look at https://godbolt.org/z/YT8bPsW9W #include <iostream>
#ifdef USE_STD_TUPLE
#include <tuple>
using std::apply;
using std::tie;
using std::tuple;
#define WRAP_TUPLE_ARGS(...) __VA_ARGS__
#else
#include "https://raw.githubusercontent.com/codeinred/tuplet/main/include/tuplet/tuple.hpp"
using tuplet::apply;
using tuplet::tie;
using tuplet::tuple;
#define WRAP_TUPLE_ARGS(...) { __VA_ARGS__ }
#endif
template <typename... DepValues>
class Foo {
public:
Foo(const DepValues&... deps)
: m_deps(WRAP_TUPLE_ARGS(deps...))
, m_slots(WRAP_TUPLE_ARGS(deps...))
{}
void dump() { apply(Foo::dumpValues<DepValues...>, this->m_deps); }
private:
template <typename... Values>
static void dumpValues(const Values&... values) {
(Foo::dumpOne(values), ...);
};
template <class Value>
static void dumpOne(const Value& value) {
std::cout << value << ", ";
}
template <typename T>
struct slot
{
explicit slot( const T& source )
{}
};
using dep_holder_t = tuple<DepValues...>;
dep_holder_t m_deps;
tuple<slot<DepValues>...> m_slots;
};
int main() {
using T = Foo<int, int>;
T t{3, 5};
t.dump();
} |
I tried to use tuplet::tuple as a optional drop-in replacement for std::tuple to check if it reduces compilation times for my use case. But compilation failed. I reproduced it on godbolt.
Any ideas? Is it principal limitation of tuplet so, some wrapper function should be called or it is a bug that can be easily fixed?
The text was updated successfully, but these errors were encountered: