I'm got a map of key type std::pair<Foo,Bar>
and value in
which I would like to insert into a map by passing the pair std::pair<std::pair<Foo,Bar> , int>
to the insert function like so (online source)
struct Foo{};
struct Bar{};
typedef std::pair<Foo,Bar> FooBar;
typedef std::pair<FooBar,int> FooBarPair;
typedef std::map<FooBar,int> FooBarMap;
struct FooBarData
{
operator const FooBarPair() const
{
return std::make_pair( std::make_pair( m_foo , m_bar ) , m_num );
}
private:
int m_num;
Foo m_foo;
Bar m_bar;
};
int main()
{
FooBarData fbd;
FooBarMap fbm;
fbm.insert( fbd );
}
clang error message
/usr/include/c++/v1/map:1041:9: note: candidate function not viable: no known conversion from 'FooBarData' to 'const value_type' (aka 'const pair<const key_type, mapped_type>') for 1st argument
insert(const value_type& __v) {return __tree_.__insert_unique(__v);}
^
/usr/include/c++/v1/map:1050:14: note: candidate function template not viable: requires 2 arguments, but 1 was provided
void insert(_InputIterator __f, _InputIterator __l)
^
/usr/include/c++/v1/map:1045:9: note: candidate function not viable: requires 2 arguments, but 1 was provided
insert(const_iterator __p, const value_type& __v)
Is there any fix along these lines?