Container in STL

Is there is any container in STL which can accept three parameters.
Like for e.g. container<int,int,int>
all the three parameters are unique.
What are the 3 parameters you want to use?
How do the three parameters relate to each other? Do you want a 3d array? What should the meaning of the three parameters be and how do you think that the container should work with those three template params? In other words, what are your requirements?
My three parameters are strings,
i need to search on the basis of any parameter into the container.
Like if i have inserted a row like a,b,c as three parameters into the container then passing "a" as parameter i should be able to retrieve b and c and in the same way if i have b then i should able to search a and c and vice versa.i am looking for such kind of functionality so that my search operation must be fast

My sample container look like
a,b,c
e,f,g and so on

what is the best way to do this operation
I suppose if your data comes in groups of 3 - then you could make a structure template:

1
2
3
4
5
6
7
template <typename T>
struct Triplet
{
    T first;
    T second;
    T third;
};


and go from there...
There isn't an STL container that'll do that directly.
Last edited on
But there is boost::multi_index_container, which will allow you log N lookups on all three fields.

Be warned I have not tried to compile this; this is off the top of my head:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>

struct MyData {
    MyData() : s1(), s2(), s3() {}

    MyData( const std::string& s1, const std::string& s2, const std::string& s3 ) :
       s1( s1 ), s2( s2 ), s3( s3 ) {}

    std::string s1;
    std::string s2;
    std::string s3;
};

struct first_string {};
struct second_string {};
struct third_string {};

typedef boost::multi_index_container<
   MyData,
   boost::multi_index::indexed_by<
      boost::multi_index::ordered_unique< boost::multi_index::tag< first_string >,
        boost::multi_index::member< MyData, std::string, &MyData::s1 > >,
      boost::multi_index::ordered_unique< boost::multi_index::tag< second_string >,
        boost::multi_index::member< MyData, std::string, &MyData::s2 > >,
      boost::multi_index::ordered_unique< boost::multi_index::tag< third_string >,
        boost::multi_index::member< MyData, std::string, &MyData::s3 > >
    >
  > MyContainer;

/* Note: Change ordered_unique to ordered_nonunique if the value is not necessarily unique. 
    Then your searches will return ranges that you have to deal with in a manner similar to multimap. */

// To use the container:
MyContainer ctr;

// Insert elements
ctr.insert( MyData( "a", "b", "c" ) );
ctr.insert( MyData( "d", "e", "f" ) );

// Find occurrence of s1 == "a".
MyContainer::index<first_string>::type::iterator i = ctr.get<first_string>().find( "a" );

// Erase it.
if( i != ctr.get<first_string>().end() )
    ctr.get<first_string>().erase( i );


I'm impressed.
Thanks for the replies, but i am not using Boost on my system(not included) as for the given framework it not there so i need to look for some different approach
EDIT: I'm stupid. This had no chance to work...
Last edited on
I think OP is looking for something that would allow for log N lookups based on any of the three fields.
Without boost, the only other thing I can come up with is three parallel data structures (std::sets<>)
each sorted on different element.
Topic archived. No new replies allowed.