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 6843403
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T00:14:27+00:00 2026-05-27T00:14:27+00:00

I want to define std::tr1::hash<boost::tuple<A,B,C> > . But I get an error that doesn’t

  • 0

I want to define std::tr1::hash<boost::tuple<A,B,C> >. But I get an error that doesn’t appear when I give a complete instantation. Here’s the code

namespace std{

namespace tr1{
template<typename A, typename B, typename C>
struct hash<boost::tuple<A,B,C> >{
    size_t operator()(const boost::tuple<A,B,C> &t) const{
        size_t seed = 0;
        boost::hash_combine(seed, t.get<0>());
        boost::hash_combine(seed, t.get<1>());
        boost::hash_combine(seed, t.get<2>());
        return seed;
    }
};

template<>
struct hash<boost::tuple<int,int,int> >{
    size_t operator()(const boost::tuple<int,int,int> &t) const{
        size_t seed = 0;
        boost::hash_combine(seed, t.get<0>());
        boost::hash_combine(seed, t.get<1>());
        boost::hash_combine(seed, t.get<2>());
        return seed;
    }
};
}
}

The first piece gives this error

unordered.hpp: In member function 'size_t std::tr1::hash<boost::tuples::tuple<A, B, C, 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> >::operator()(const boost::tuples::tuple<A, B, C, 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>&) const':
unordered.hpp:12: error: expected primary-expression before ')' token
unordered.hpp:13: error: expected primary-expression before ')' token
unordered.hpp:14: error: expected primary-expression before ')' token

and the second compiles just fine. What’s wrong with the first template? I’m using gcc 4.3.4.

  • 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-27T00:14:28+00:00Added an answer on May 27, 2026 at 12:14 am

    You need to use the .template keyword:

    template<typename A, typename B, typename C>
    struct hash<boost::tuple<A,B,C> >{
        size_t operator()(const boost::tuple<A,B,C> &t) const{
            size_t seed = 0;
            boost::hash_combine(seed, t.template get<0>());
            boost::hash_combine(seed, t.template get<1>());
            boost::hash_combine(seed, t.template get<2>());
            return seed;
        }
    };
    

    This is required because type of t depends on three template paramaters (and so t is type-dependent), and get<0> is the name of a template specialization. From the C++ standard — §14.2/4:

    When the name of a member template specialization appears after . or -> in a postfix-expression … and the object expression of the postfix-expression is type-dependent … the member template name must be prefixed by the keyword template. …

    This requirement exists to allow templates to be parsed before their type arguments are known.

    For example, consider:

    f . set < 0 > ( 2 == 3 )
    

    Without the .template rule, this could interpreted as two different things:

    //A call to an instantiation of a member function template
    //in this case equivalent to f.template set<0>(false)
    f.set<0>(2 == 3)
    //A series of comparison operations, in this case equivalent to
    //f.set < 0
    f.set < 0 > (2 == 3)
    

    The actual rules allow f . set < 0 > ( 2 == 3 ) to be unambiguously parsed as a series of comparison operations. They also mean that t.get<0>() is parsed as t.get < 0 > (). The expected primary-expression is meant to be in the empty ().

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

Sidebar

Related Questions

I want to define a class that supports __getitem__ , but does not allow
I want to define a class method that has access to a local variable.
I want to define a constant that should be available in all of the
I have an std::map , and I would like to define an iterator that
I want to define a macro that can be invoked in different places (at
I want to define a class MyStream so that: MyStream myStream; myStream << 1
I want to define my own datatype that can hold a single one of
This code below compiles fine with VS2010 but doesn't want to compile with gcc
i have to define a variable that i am using in a program but
I want to define something like this in php : $EL = \n<br />\n;

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.