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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T10:52:43+00:00 2026-05-18T10:52:43+00:00

I’m currently writing a generic vector template class (the geometric entity, not the container)

  • 0

I’m currently writing a generic vector template class (the geometric entity, not the container) with the following signature…


template< typename T, unsigned N >
class vector
{...}

… where T is an arithmetic type and N, the dimension. I would like to define the cross product as an overload of operator ^ (located inside class definition) and enable it only when N == 3. What I’ve have now is:


typename boost::lazy_enable_if_c< (N == 3), vector >::type
inline operator ^(const vector &rhs) const
{
    vector ret;
    ret(0) = val_[1] * rhs(2) - val_[2] * rhs(1);
    ret(1) = val_[2] * rhs(0) - val_[0] * rhs(2);
    ret(2) = val_[0] * rhs(1) - val_[1] * rhs(0);
    return ret;
}

Unfortunately, instantiating this template with N != 3, even though operator ^ isn’t referenced, yields the following error:


error: no type named ‘type’ in ‘struct boost::lazy_enable_if_c < false, flare::math::vector < flare::math::fixed < short int, 8u >, 2u > >’

What am I doing wrong? Is there an alternative to boost::enable_if in such case?

Thank you very much.

  • 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-18T10:52:43+00:00Added an answer on May 18, 2026 at 10:52 am

    The proximal cause of the error message is that, according to the docs, “The second argument of lazy_enable_if must be a class type that defines a nested type named type whenever the first parameter (the condition) is true.” That’s clearly not satisfied here (unless your vector type just happens to contain typedef something type;).

    You don’t need lazy_... here. According to the docs, that’s only needed if the 2nd arg could be undefined (e.g. if the 2nd arg was typename foo<T>::bar, and the bar type is not defined for all types T). vector (which here means vector<T, N>) will always be defined.

    So definitely try getting rid of lazy_, or alternatively create a do-nothing traits class template <typename T> struct nop { typedef T type; }; and replace the 2nd arg to lazy_enable_if_c with nop<vector>. But my guess is you’ve already tried the former at least. 🙂

    And now I see why that won’t work. According to the standard 14.7.1/1:

    Unless a class template
    specialization has been explicitly
    instantiated (14.7.2) or explicitly
    specialized (14.7.3), the class
    template specialization is implicitly
    instantiated when the specialization
    is referenced in a context that
    requires a completely-defined object
    type or when the completeness of the
    class type affects the semantics of
    the program. The implicit
    instantiation of a class template
    specialization causes the implicit
    instantiation of the declarations, but
    not of the definitions or default
    arguments, of the class member
    functions, member classes, static data
    members and member templates;

    So anything that causes the class to be instantiated will try to instantiate declarations for all methods, which will fail when N != 3. So it looks like you’ll need to use an always-present method that hands off to a function template instead. Don’t worry, any decent compiler will still be able to inline through this:

    template< typename T, unsigned N > class vector;   // Fwd decl.
    
    template< typename T, unsigned N >
    inline boost::enable_if_c< (N == 3), vector<T, N> >::type
    magic(const vector<T, N>& lhs, const vector<T, N>& rhs) {
        /* Do the calculation as before... */
        return ret;
    }
    
    template< typename T, unsigned N >
    class vector {
        ...
        inline vector operator ^(const vector &rhs) const {
            return magic(*this, rhs);
        }
    };
    

    This will work because the member function definitions are not instantiated unless they are actually called (or their addresses are taken etc.).

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

Sidebar

Related Questions

I am currently running into a problem where an element is coming back from
I want use html5's new tag to play a wav file (currently only supported
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a JSP page retrieving data and when single or double quotes are
Seemingly simple, but I cannot find anything relevant on the web. What is the
Does anyone know how can I replace this 2 symbol below from the string
this is what i have right now Drawing an RSS feed into the php,
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and

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.