Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 582387
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T14:40:53+00:00 2026-05-13T14:40:53+00:00

I’ve got a strange problem with templates and namespaces… I have the following code

  • 0

I’ve got a strange problem with templates and namespaces…

I have the following code which compiles fine..

using namespace boost::multi_index;

template < typename OT, typename KT, KT (OT::* KM)() const, typename KC, typename CMP >
class OrderBook
{
public:
    OrderBook() {}
    ~OrderBook() {}

    typedef multi_index_container<
        OT,
        indexed_by<
            ordered_unique<
                const_mem_fun< OT, KT, KM >,
                KC
            >,
            ordered_unique<
                identity< OT >,
                CMP
            >
        >
    > Container;

    typedef typename Container::template nth_index< 0 >::type index_0;
    typedef typename Container::template nth_index< 1 >::type index_1;

    typedef typename index_0::const_iterator const_iterator_0;
    typedef typename index_1::const_iterator const_iterator_1;

    const_iterator_0 begin0() const { return _container.get<0>().begin(); }
    const_iterator_0 end0() const { return _container.get<0>().end(); }


public:
    Container _container;
};

However, due to a namespace collision when I insert this code into another project I have to have… (Notice how I’ve had to remove the using namespace boost::multi_index and manually specify it where needed

template < typename OT, typename KT, KT (OT::* KM)() const, typename KC, typename CMP >
class OrderBook
{
public:
    OrderBook() {}
    ~OrderBook() {}

    typedef boost::multi_index::multi_index_container<
        OT,
        boost::multi_index::indexed_by<
            boost::multi_index::ordered_unique<
                boost::multi_index::const_mem_fun< OT, KT, KM >,
                KC
            >,
            boost::multi_index::ordered_unique<
                boost::multi_index::identity< OT >,
                CMP
            >
        >
    > Container;

    typedef typename Container::template nth_index< 0 >::type index_0;
    typedef typename Container::template nth_index< 1 >::type index_1;

    typedef typename index_0::const_iterator const_iterator_0;
    typedef typename index_1::const_iterator const_iterator_1;

    const_iterator_0 begin0() const { return _container.get<0>().begin(); }
    const_iterator_0 end0() const { return _container.get<0>().end(); }


public:
    Container _container;
};

Which gives me the following error from g++.

In member function 'typename boost::multi_index::multi_index_container<OT, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::const_mem_fun<OT, KT, KM>, KC, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::identity<Value>, CMP, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<_CharT> >::nth_index<0>::type::const_iterator OrderBook<OT, KT, KM, KC, CMP>::begin0() const':

error: expected primary-expression before ')' token


In member function 'typename boost::multi_index::multi_index_container<OT, boost::multi_index::indexed_by<boost::multi_index::ordered_unique<boost::multi_index::const_mem_fun<OT, KT, KM>, KC, mpl_::na>, boost::multi_index::ordered_unique<boost::multi_index::identity<Value>, CMP, mpl_::na>, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na, mpl_::na>, std::allocator<_CharT> >::nth_index<0>::type::const_iterator OrderBook<OT, KT, KM, KC, CMP>::end0() const':

error: expected primary-expression before ')' token

Sorry for the long error messages, I did consider cleaning them up but I thought I’d better leave them intact in case I removed something crucial.

I tried this…

typedef typename Container::template boost::multi_index::nth_index< 0 >::type index_0;
typedef typename Container::template boost::multi_index::nth_index< 1 >::type index_1;

and it just made g++ even madder 🙁

Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T14:40:53+00:00Added an answer on May 13, 2026 at 2:40 pm

    Prefix get<0>() with template:

    const_iterator_0 begin0() const { return _container.template get<0>().begin(); }
    const_iterator_0 end0  () const { return _container.template get<0>().end();   }
    

    Similar to typename for dependent types, dependent templates have to be prefixed by template:

    struct X {
        template<class T> void f();
    };
    
    template<class T>
    void test() {
        T::f<int>(); // ill-formed
        T::template f<int>(); // ok
    }
    
    // ...
    test<X>();
    

    And for the curious, that is §14.2/4:

    When the name of a member template
    specialization appears after . or ->
    in a postfix-expression, or after
    nested-name-specifier in a
    qualified-id, and the
    postfix-expression or qualified-id
    explicitly depends on a
    template-parameter (14.6.2), the
    member template name must be prefixed
    by the keyword template. Otherwise the
    name is assumed to name a
    non-template.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 380k
  • Answers 380k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer NSApplication.AboutPanelOptionKey May 14, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer You can put your pdf in separate dir: /trunk /branches… May 14, 2026 at 9:46 pm
  • Editorial Team
    Editorial Team added an answer It won't really matter if you CNAME or A record… May 14, 2026 at 9:46 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.