473,587 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

boost::tuple with uniform types

Here is some tuple (triple in this case) with uniform types (for
instance, double):
boost::tuple<do uble, double, doublet;

Is there any way (in boost::tuple) to define such tuples something
like
uniform_tuple <3, doublet; ?

Alex Vinokur
Aug 5 '08 #1
4 2418
On Aug 5, 8:15*am, Alex Vinokur <ale...@users.s ourceforge.netw rote:
Here is some tuple (triple in this case) with uniform types (for
instance, double):
boost::tuple<do uble, double, doublet;

Is there any way (in boost::tuple) to define such tuples something
like
uniform_tuple <3, doublet; ?
Not inherently, but you could use your own template typedefs:

template<int count, typename Tstruct uniform_tuple;
template<typena me Tstruct uniform_tuple<2 ,T{ typedef
boost::tuple<T, T type; };
template<typena me Tstruct uniform_tuple<3 ,T{ typedef
boost::tuple<T, T,T type; };
template<typena me Tstruct uniform_tuple<4 ,T{ typedef
boost::tuple<T, T,T,Ttype; };
// etc.

Then you use it like:

uniform_tuple<3 ,double>::type t;

You could play with Boost's MPL type lists and such to make it more
generic and have the preprocessor generate the redundant code, but
that may be overkill for what you want to do (not to mention beyond
the scope of this group, unlike tuple talk). Also the next version of
the standard will make template typedefs of thing a little prettier,
but you'll have to live with the ugliness for now.

Cheers! --M
Aug 5 '08 #2
On Aug 5, 9:18*am, mlimber <mlim...@gmail. comwrote:
On Aug 5, 8:15*am, Alex Vinokur <ale...@users.s ourceforge.netw rote:
Here is some tuple (triple in this case) with uniform types (for
instance, double):
boost::tuple<do uble, double, doublet;
Is there any way (in boost::tuple) to define such tuples something
like
uniform_tuple <3, doublet; ?

Not inherently, but you could use your own template typedefs:

template<int count, typename Tstruct uniform_tuple;
template<typena me Tstruct uniform_tuple<2 ,T{ typedef
boost::tuple<T, T* * type; };
template<typena me Tstruct uniform_tuple<3 ,T{ typedef
boost::tuple<T, T,T* type; };
template<typena me Tstruct uniform_tuple<4 ,T{ typedef
boost::tuple<T, T,T,Ttype; };
// etc.

Then you use it like:

uniform_tuple<3 ,double>::type t;

You could play with Boost's MPL type lists and such to make it more
generic and have the preprocessor generate the redundant code, but
that may be overkill for what you want to do (not to mention beyond
the scope of this group, unlike tuple talk). Also the next version of
the standard will make template typedefs of thing a little prettier,
but you'll have to live with the ugliness for now.

Cheers! --M
Just by coincidence I had just written the following code. It doesn't
help the OP because it uses C++0X features (variadic templates). So
this is just a tantalizing peek at the future as opposed to genuine
help. :-\ But I thought it might be interesting nonetheless.

template <class Tuple, class U, std::size_t Nstruct
make_array_imp;

template <class ...Up, class U>
struct make_array_imp< std::tuple<Up.. .>, U, 0>
{
typedef std::tuple<Up.. .type;
};

template <class ...Up, class U, std::size_t N>
struct make_array_imp< std::tuple<Up.. .>, U, N>
{
typedef typename make_array_imp< std::tuple<Up.. ., U>, U,
N-1>::type type;
};

template <class U, std::size_t N>
struct make_array
{
typedef typename make_array_imp< std::tuple<>, U, N>::type
type;
};

typedef typename make_array<T, 3>::type array; // tuple<T, T, T>

-Howard

Aug 5 '08 #3
Howard Hinnant wrote:
>
typedef typename make_array<T, 3>::type array; // tuple<T, T, T>

Why not abbreviate to std::array<T,N> ?

regards
Andy Little
Aug 5 '08 #4
On Aug 5, 7:29*pm, kwikius <a...@servocomm .freeserve.co.u kwrote:
Howard Hinnant wrote:
* * typedef typename make_array<T, 3>::type array; *// tuple<T, T, T>

Why not abbreviate to std::array<T,N> ?
I am hopeful that will be a good solution. std::array is currently
lacking a move constructor and the ability to interoperate with tuple
and pair (other tuple-like types).

-Howard

Aug 6 '08 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

205
10518
by: Jeremy Siek | last post by:
CALL FOR PAPERS/PARTICIPATION C++, Boost, and the Future of C++ Libraries Workshop at OOPSLA October 24-28, 2004 Vancouver, British Columbia, Canada http://tinyurl.com/4n5pf Submissions
3
3376
by: Misiu | last post by:
Hello everybody, How to avoid using struct IsDataType for comparison for find_if algorithm but use something like that what is now commented out in the code below? Regards, Misiu template<typename T>
1
1678
by: Noah Roberts | last post by:
A while back I posted a question either here or to the boost user list about how to iterate through a vector of strings and perform a lexical cast on them into elements of a tuple. I was working with sqlite3 and found myself repeatedly writing code like so: t.get<0>() = boost::lexical_cast<double>(vect); t.get<1>() =...
6
4937
by: Lambda | last post by:
Hi All, I'm trying Boost in my Ubuntu machine for the first time. It's a simple code that use tuple. But when I g++ it, it says: tuple: no such file or directory I installed boost 1.33.1, I proved it with apt-get install
2
2302
by: Man4ish | last post by:
I have created Graph object without vertex and edge property.It is working fine. #include <boost/config.hpp> #include <iostream> #include <vector> #include <string> #include <boost/graph/adjacency_list.hpp> #include <boost/tuple/tuple.hpp> #include <set> using namespace std;
0
345
by: Jerzie.Klenchier | last post by:
Hi all, I'm having some difficulty in getting the following piece of code to compile: #include <iostream> #include <deque> #include <algorithm> #include <boost/tuple/tuple.hpp> #include <boost/lambda/lambda.hpp>
1
2618
by: Tim H | last post by:
Compiling with g++ 4: This line: if_then_else_return(_1 == 0, 64, _1) When called with a bignum class as an argument yields: /usr/include/boost/lambda/if.hpp: In member function 'RET boost::lambda::lambda_ functor_base<boost::lambda::other_action<boost::lambda::ifthenelsereturn_action>
1
2311
by: Alex Vinokur | last post by:
Hi, Is it possible to get number of elements in the tuple boost? For instance, boost::tuple<int, string, boolt; Number of elements in that tuple is 3. I need to get that number.
1
2159
by: Alex Vinokur | last post by:
Suppose we have the following tuple boost::tuple<int, std::string, bool, doublet (/* initialization */) I would like to print that tuple using get_head() and get_tail() in while-loop while (/* What is a cindition */) { std::cout << t.get_head() << std::endl; // What to do with t.get_tail()
0
7915
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7843
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
1
7967
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8220
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6619
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5712
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3840
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3872
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2347
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.