Boost logo

Boost :

Subject: Re: [boost] [assign] How to create a container wrapper for tuple_list_of
From: Jeffrey Lee Hellrung, Jr. (jeffrey.hellrung_at_[hidden])
Date: 2012-04-26 17:07:24


On Thu, Apr 26, 2012 at 1:53 PM, Robert Dailey <rcdailey.lists_at_[hidden]>wrote:

> I have a vector of boost::tuple objects that is a member variable in a
> class of mine. I want to be able to create an instance of my wrapper class
> and construct it off of a tuple_list_of(), and essentially forward those
> values to the container itself. I haven't seen a way to do this yet. An
> example is below. Note that my constructor in the class was my attempt to
> get this working, but instead it will not compile. For some reason
> boost.assign thinks that the EnumErrorInfo class is the container.
>
> template<class T>
> class EnumErrorInfo
> {
> public:
> typedef boost::tuple<T, char const*, char const*> Tuple;
> typedef std::vector<Tuple> TupleVector;
>
> EnumErrorInfo( TupleVector const& assignment )
> : m_errorInfo( assignment )
> {}
>
> Tuple const& getErrorInfo( T error_code )
> {
> TupleVector::const_iterator it =
> std::find_if( m_errorInfo.begin(), m_errorInfo.end(), MatchErrorCodePred(
> error_code ) );
>
> if( it != m_errorInfo.end() ) {
> return *it;
> }
>
> static Tuple const unknown_info( error_code, "????", "No error info
> available for this code" );
> return unknown_info;
> }
>
> private:
> class MatchErrorCodePred
> {
> public:
> MatchErrorCodePred( T error_code )
> : m_errorCode( error_code )
> {}
>
> bool operator() ( Tuple const& t )
> {
> return t.get<0>() == m_errorCode;
> }
>
> private:
> DomInterfaceErrors m_errorCode;
> };
>
> TupleVector m_errorInfo;
> };
>
> And here is how I'd like to initialize the class:
>
> EnumErrorInfo<DomInterfaceErrors> g_errorInfo = tuple_list_of
> ( GDE_OK, "GDE_OK", "DBL: Opeartion successfully completed" )
> ( GDE_GDD_DIRUSERS, "GDE_GDD_DIRUSERS", "AQX: Unable to get directory
> users." )
> ;
>

I'm not familiar with Boost.Assign, but perhaps you should take a look at

http://www.boost.org/doc/libs/1_49_0/libs/assign/doc/index.html#extensions

?

- Jeff


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk