Boost logo

Boost Users :

From: Kowalke Oliver (QD IT PA AS) (Oliver.Kowalke_at_[hidden])
Date: 2008-01-08 04:24:58


Hello,
I want to do an range selection over an composit key but I get compiler errors like:
/home/kowalke/Projects/test_multi_index/src/test_multi_index.cpp:85: instantiated from here
/opt/boost/include/boost-1_34/boost/multi_index/ordered_index.hpp:978: error: no match for call to '(boost::tuples::tuple<boost::multi_index::detail::unbounded_type, bool, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type>) (boost::multi_index::composite_key_result<boost::multi_index::composite_key<item, boost::multi_index::member<item, double, &item::function>, boost::multi_index::member<item, bool, &item::active>, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type, boost::tuples::null_type> >)'

I've appended a test app.
Thanks for advice!
regards, Oliver

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#include <algorithm>
#include <iostream>
#include <utility>
#include <cstdlib>
#include <stdexcept>
#include <string>
#include <boost/foreach.hpp>
#include <boost/multi_index_container.hpp>
#include <boost/multi_index/member.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/composite_key.hpp>

#include <boost/lambda/lambda.hpp>

namespace mi = boost::multi_index;

struct item
{
        double function;
        bool active;

        item(
                double function_,
                bool active_)
        : function( function_), active( active_)
        {}
};

struct idx_tag {};

typedef mi::multi_index_container<
        item,
        mi::indexed_by<
                mi::ordered_unique<
                        mi::tag< idx_tag >,
                        mi::composite_key<
                                item,
                                mi::member<
                                        item,
                                        double,
                                        & item::function
>,
                                mi::member<
                                        item,
                                        bool,
                                        & item::active
>
>,
                        mi::composite_key_compare<
                                std::greater< double >,
                                std::greater< bool >
>
>
>
> table;

typedef table::index< idx_tag >::type idx_type;

int main( int argc, char *argv[])
{
        try
        {
                table tbl;
                tbl.insert( item( -1.1, true) );
                tbl.insert( item( 1., true) );
                tbl.insert( item( 0., true) );
                tbl.insert( item( 1.1, false) );
                tbl.insert( item( -1., true) );
                tbl.insert( item( -1., false) );

                idx_type & idx( tbl.get< idx_tag >() );

                std::pair<
                        idx_type::iterator,
                        idx_type::iterator
> p(
                        idx.range(
                                boost::make_tuple( mi::unbounded, true),
                                boost::make_tuple(
                                        boost::lambda::_1 >= 0.,
                                        true) ) );

                for ( ; p.first != p.second; ++p.first)
                        std::cout << p.first->function << " " << std::boolalpha << p.first->active << std::endl;

                return EXIT_SUCCESS;
        }
        catch ( std::exception const& e)
        { std::cerr << e.what() << std::endl; }
        catch ( ... )
        { std::cerr << "unhandled exception" << std::endl; }

        return EXIT_FAILURE;
}


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net