vendredi 16 octobre 2020

Cannot compile: error: expected primary-expression before '(' token

I cannot get this compile:

// main.cpp

#include <boost/multi_index_container.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <boost/multi_index/indexed_by.hpp>
#include <boost/multi_index/mem_fun.hpp>
#include <boost/multi_index/ordered_index.hpp>
#include <boost/multi_index/tag.hpp>

using namespace boost::multi_index;


struct by_attrs{};

// Generic MultiIndex that wraps boost::multi_index
template<typename Container>
class MultiIndex
{
public:

    // line below is "intuitive" but fails. g++ suggests adding "template"
    // typedef typename Container::index<by_attrs>::type::iterator attr_iterator;

    // ...so I did
    typedef typename Container::template index<by_attrs>::type::iterator attr_iterator;


    template<typename FromArgs, typename ToArgs>
    std::pair<attr_iterator, attr_iterator>
    fetch_range(FromArgs&& from, ToArgs&& to)
    const
    {  
        return std::pair<attr_iterator, attr_iterator>(
                _container.get<by_attrs>().lower_bound(from),
                _container.get<by_attrs>().upper_bound(to)
        );
    }  

private:

    Container _container;
};


class Foo
{
public:
    int bar() const
    {  
        return 1; 
    }  
};


typedef multi_index_container<
    Foo,
    indexed_by<
        ordered_unique<
            tag<by_attrs>,
            composite_key<
                Foo,
                const_mem_fun<
                    Foo,
                    int,
                    &Foo::bar
                >,
            >
        >
    >  
> FooMultiIndexContainer;


typedef MultiIndex<FooMultiIndexContainer> FooMultiIndex;


int main()
{
    FooMultiIndex foo_index;
}

Error (g++ main.cpp -std=c++17):

In member function 'std::pair<typename Container::index<by_attrs>::type::iterator, typename Container::index<by_attrs>::type::iterator> MultiIndex<Container>::fetch_range(FromArgs&&, ToArgs&&) const': main.cpp:28:55: error: expected primary-expression before '(' token 28 | return std::pair<attr_iterator, attr_iterator>(

Aucun commentaire:

Enregistrer un commentaire