On Mon, April 23, 2007 19:34, Joaquín Mª López Muñoz wrote:
I don't know what the problem is but it looks like there's more to it
than you described. Please see the attached compilable snippet mimicking
your scenario: it works OK for GCC 3.2, and it uses the string const&
version of create_type(). Do you observe otherwise? When you say that
the former fails: do you mean you get a compiler error? If so, what's
it like?
Well, what I mean is the following sample:
#include
#include
#include
#include
#include <utility>
#include <string>
#include <iostream>
namespace mi=boost::multi_index;
typedef int some_type;
typedef std::pair key_value_pair;
//actually this is a predefined type
boost::array predefined_types =
{
key_value_pair("test1", NULL)
, key_value_pair("test2", NULL)
, key_value_pair("test3", NULL)
, key_value_pair("test4", NULL)
, key_value_pair("test5", NULL)
};
struct hash{}; //tag used to retrieve values
typedef mi::multi_index_container
<
key_value_pair,
mi::indexed_by
<
mi::hashed_unique
<
mi::tag<hash>,
BOOST_MULTI_INDEX_MEMBER(key_value_pair, std::string, first)
>
types_map;
types_map types_(predefined_types.begin(), predefined_types.end());
inline void create_type(std::string const& name)
{
types_.insert(std::make_pair(name, NULL));
}
inline bool has_type(std::string const& name)
{
types_map::index<hash>::type::const_iterator i=types_.get<hash>().find(name), end =
types_.get<hash>().end();
return i!=end;
}
int main()
{
//std::string s("hello");
//create_type(s);
std::string s2("test3");
std::cout << "multi_index instance contains string \""+s2+"\": " << (has_type(s2)?"yes":"no");
}
But in a clean environment it works fine and 'has_type' finds the string. May be I have some
globally available identifier, which returns the wrong string, and therefore fails... I will
double check it and get back to this post if I identify smth. Many thanks for your great support!
With Kind Regards,
Ovanes Markarian