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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T01:25:55+00:00 2026-05-27T01:25:55+00:00

I have some generic code which implements Pareto rule. It seems like well-formed code.

  • 0

I have some generic code which implements Pareto rule. It seems like well-formed code.

GCC 4.4 compiler messages about errors for newResult.set<Criterion>( criterion() ); expression. But I can’t found problem.

Full error log:

trunk$ g++ -std=c++0x -o test test.cpp 
t6.cpp: In member function ‘bool Pareto<Minimize<T>, Types ...>::operator()(Map&, Map&)’:
t6.cpp:24: error: expected primary-expression before ‘>’ token
t6.cpp:26: error: expected primary-expression before ‘>’ token
t6.cpp:26: error: expected primary-expression before ‘)’ token
t6.cpp:26: error: expected primary-expression before ‘>’ token
t6.cpp:26: error: expected primary-expression before ‘)’ token
t6.cpp: In member function ‘bool Pareto<Maximize<T>, Types ...>::operator()(Map&, Map&)’:
t6.cpp:43: error: expected primary-expression before ‘>’ token
t6.cpp:45: error: expected primary-expression before ‘>’ token
t6.cpp:45: error: expected primary-expression before ‘)’ token
t6.cpp:45: error: expected primary-expression before ‘>’ token
t6.cpp:45: error: expected primary-expression before ‘)’ token

Full code listing:

// TypeMap
template < typename ... Tail >
struct Holder;

template <typename ValueType, typename Head, typename ... Tail >
struct Holder<ValueType, Head, Tail ... > :
    public Holder<ValueType, Head>,
    public Holder<ValueType, Tail ... >
{};

template <typename ValueType, typename Head >
struct Holder<ValueType, Head>
{
    ValueType value;
};

template < typename ... Types >
struct TypeMap;

template <typename ValueType, typename ... Types >
struct TypeMap<ValueType, Types ... > :
    public Holder<ValueType, Types ... >
{
    template <typename T>
    void set(const ValueType& value)
    {
        ((Holder<ValueType, T>*)this)->value = value;
    }

    template <typename T>
    ValueType get()
    {
        return ((Holder<ValueType, T>*)this)->value;
    }
};

// Objectives
template <typename Criterion> struct Maximize : public Criterion {};
template <typename Criterion> struct Minimize : public Criterion {};

// Criteria
struct Criterion1{ double operator()(){ return 0; }};
struct Criterion2{ double operator()(){ return 0; }};

// Pareto rule
template < typename ... Types > struct Pareto;

template < typename T, typename ... Types >
struct Pareto<Minimize<T>, Types ... >
{
    template< typename Map >
    bool operator()(Map& oldResult, Map& newResult)
    {
        typedef Minimize<T> Criterion;
        Criterion criterion;

        // ERROR HERE !!!
        newResult.set<Criterion>( criterion() );

        if(newResult.get<Criterion>() >= oldResult.get<Criterion>())
            return false;

        Pareto<Types ... > pareto;
        return pareto(oldResult, newResult);
    }
};

template < typename T, typename ... Types >
struct Pareto<Maximize<T>, Types ... >
{
    template< typename Map >
    bool operator()(Map& oldResult, Map& newResult)
    {
        typedef Maximize<T> Criterion;
        Criterion criterion;

        // ERROR HERE !!!
        newResult.set<Criterion>( criterion() );

        if(newResult.get<Criterion>() <= oldResult.get<Criterion>())
            return false;

        Pareto<Types ... > pareto;
        return pareto(oldResult, newResult);
    }
};

template<>
struct Pareto<>
{
    template<typename Map>
    bool operator()(Map& oldResult, Map& newResult)
    {
        oldResult = newResult;
        return true;
    }
};

int main()
{
    TypeMap<double, Minimize<Criterion1>, Maximize<Criterion2>> oldResult, newResult;

    Pareto<Minimize<Criterion1>, Maximize<Criterion2>> pareto;
    pareto(oldResult, newResult);
}
  • 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-27T01:25:56+00:00Added an answer on May 27, 2026 at 1:25 am

    Found it:

    newResult.template set<Criterion>( criterion() );
    
    if(newResult.template get<Criterion>() >= oldResult.template get<Criterion>())
        return false;
    

    You have to qualify the member function templates for the compiler in this case.
    The lexer wouldn’t be able to decide (at the time of template declaration, not instantiation) whether <Criterion means the start of a template parameter list or, instead, a comparison operator.

    See

    • Using the template keyword as qualifier

    • What is the .template and ::template syntax about? (Comeau)

    • Standard, § 14.2, sub 4. and 5., noteworthy:

      [ Note: As is the case with the typename prefix, the template prefix is allowed in cases where it is
      not strictly necessary; i.e., when the nested-name-specifier or the expression on the left of the -> or . is not
      dependent on a template-parameter, or the use does not appear in the scope of a template. —end note ]

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

Sidebar

Related Questions

I have some generic code which I cannot figure out how to legitimately prevent
Here's the situation: We have some generic graphics code that we use for one
I have to work on some code that's using generic lists to store a
I have some generic types, like the following: public struct Tuple<T1, T2> { ...
I have a peculiar problem here. I want to extract some generic types, which
Attempting to generics-ify some legacy code, I'm stuck. I have a ParentObject which wraps
OK so I'm looking a some code which looks roughly like this: void DoSomething(object
I have a problem with slashes! I have some jQuery for handling generic dialogs
I have a generic with some filenames (LIST1) and another biggeneric with a full
I'm trying to build my first generic list and have run into some problems.

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.