boost-tuples

Sum the components of a tuple up by using std::get, std::tuple_size, std::tuple_element

╄→гoц情女王★ 提交于 2020-01-11 03:25:08
问题 I've got a custom class that has a tuple-like interface. Because I want my code to be as generic as possible, I thought that it would be a good idea to base my algorithms on the functions std::get , std::tuple_size , std::tuple_element so you just have to specialize these functions to use my algorithms. Let's call the concept that requires these function specializations Tuple . Now I am trying to sum up the components of a Tuple . The function declaration should be something like this:

no == defined for boost::tuples

 ̄綄美尐妖づ 提交于 2020-01-05 04:26:09
问题 I have this code: ... #include "boost/tuple/tuple_comparison.hpp" ... template <typename ReturnType, typename... Args> function<ReturnType(Args...)> memoize(const Args && ... args) { using noRef = boost::tuple<typename std::remove_reference<Args>::type...>; static map<noRef, ReturnType, less<>> cache; auto key = std::tie(noRef{ boost::make_tuple(args ...) }); auto it = cache.lower_bound(key); ReturnType result; if (it->first == key) { ... But when I try to compile it I receive this error:

C++ Tuple of Boost.Range - get Tuple of element types?

那年仲夏 提交于 2020-01-03 17:48:10
问题 I am experimenting with Boost.Range and the Boost Tuple. If I have a Tuple of ranges, how can I typedef a Tuple or the corresponding element values? To put this another way, what do I put in place of /*?*/ here: typedef boost::tuples::tuple<std::vector<int>&, char[]> TupleOfRanges; typedef /*?*/ TupleOfElements; I can do this by hand, of course and I would write: typedef boost::tuples::tuple<int, char> TupleOfElements; Or even: typedef typename boost::tuples::element<0, TupleOfRanges>::type

Why can't std::tuple be element-wise constructed with a std::tuple of compatible types?

和自甴很熟 提交于 2019-12-21 07:28:24
问题 I can't initialize std::tuple elements element-wise from a std::tuple of compatible types. Why doesn't it work as with boost::tuple ? #include <tuple> #include <boost/tuple/tuple.hpp> template <typename T> struct Foo { // error: cannot convert 'std::tuple<int>' to 'int' in initialization template <typename U> Foo(U &&u) : val(std::forward<U>(u)) {} T val; }; int main() { boost::tuple<Foo<int>>{boost::tuple<int>{}}; // ok auto a = boost::tuple<int>{}; boost::tuple<Foo<int>>{a}; // ok std:

Is Boost.Tuple compatible with C++0x variadic templates?

非 Y 不嫁゛ 提交于 2019-12-18 17:03:37
问题 I was playing around with variadic templates (gcc 4.5) and hit this problem : template <typename... Args> boost::tuple<Args...> my_make_tuple(Args... args) { return boost::tuple<Args...>(args...); } int main (void) { boost::tuple<int, char> t = my_make_tuple(8, 'c'); } GCC error message : sorry, unimplemented: cannot expand 'Arg ...' into a fixed-length argument list In function 'int my_make_tuple(Arg ...)' If I replace every occurrence of boost::tuple by std::tuple , it compiles fine. Is

Tuples of unknown size/parameter types

心不动则不痛 提交于 2019-12-10 22:00:41
问题 I need to create a map, from integers to sets of tuples, the tuples in a single set have the same size. The problem is that the size of a tuple and its parameter types can be determined at runtime, not compile time. I am imagining something like: std::map<int, std::set<boost::tuple> > but not exctly sure how to exactly do this, bossibly using pointers. The purpose of this is to create temporary relations (tables), each with a unique identifier (key), maybe you have another approach. 回答1: The

boost::bind doesn't work with boost::tuple::get<N>()

£可爱£侵袭症+ 提交于 2019-12-10 15:59:59
问题 I am trying to use boost::bind and STL with boost::tuple , but each time I try to compile I get the following error. error: call of overloaded ‘bind(<unresolved overloaded function type>, boost::arg<1>&)’ is ambiguous Do you know what I am doing wrong here and why is only for the boost::arg<1> ? Thanks AFG #include <iostream> #include <algorithm> #include <vector> #include <cstdio> #include <boost/tuple/tuple.hpp> #include <boost/assign.hpp> #include <boost/bind.hpp> int main( int argc, const

Why can't std::tuple be element-wise constructed with a std::tuple of compatible types?

本秂侑毒 提交于 2019-12-05 02:20:14
I can't initialize std::tuple elements element-wise from a std::tuple of compatible types. Why doesn't it work as with boost::tuple ? #include <tuple> #include <boost/tuple/tuple.hpp> template <typename T> struct Foo { // error: cannot convert 'std::tuple<int>' to 'int' in initialization template <typename U> Foo(U &&u) : val(std::forward<U>(u)) {} T val; }; int main() { boost::tuple<Foo<int>>{boost::tuple<int>{}}; // ok auto a = boost::tuple<int>{}; boost::tuple<Foo<int>>{a}; // ok std::tuple<Foo<int>>{std::tuple<int>{}}; // fails with rvalue auto b = std::tuple<int>{}; std::tuple<Foo<int>>{b

boost tuple: increasing maximum number of elements

拜拜、爱过 提交于 2019-12-03 17:03:22
问题 The boost tuple documentation says: The current version supports tuples with 0-10 elements. If necessary, the upper limit can be increased up to, say, a few dozen elements. However, I could not find where it says how to do this. I would like the tuple to have BOOST_MPL_LIMIT_VECTOR_SIZE elements (20 by default). This is because I am mapping between mpl::vectors and boost::tuples and would like all the containers to have the same number of elements. 回答1: The tuple class is declared in the

boost tuple: increasing maximum number of elements

北城余情 提交于 2019-12-03 06:00:35
The boost tuple documentation says: The current version supports tuples with 0-10 elements. If necessary, the upper limit can be increased up to, say, a few dozen elements. However, I could not find where it says how to do this. I would like the tuple to have BOOST_MPL_LIMIT_VECTOR_SIZE elements (20 by default). This is because I am mapping between mpl::vectors and boost::tuples and would like all the containers to have the same number of elements. The tuple class is declared in the following way: // - tuple forward declaration ----------------------------------------------- template < class