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

  • Home
  • SEARCH
  • 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 8687077
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:01:42+00:00 2026-06-12T23:01:42+00:00

Consider the following simplified template meta-programming code that implements an Angle class that is

  • 0

Consider the following simplified template meta-programming code that implements an Angle class that is internally storing the modulo 360 degrees reduced value.

#include <iostream>
#include <typeinfo>

template<int N, int D>
struct Modulus
{
        static auto const value = N % D;
};

template<int N>
struct Angle
{
        static auto const value = Modulus<N, 360>::value; // ERROR
        //static int const value = Modulus<N, 360>::value;  // OK
        //static auto const value = N % 360;                // OK

        typedef Angle<value> type;
};

int main()
{
        std::cout << typeid(Angle<30>::type).name() << "\n";
        std::cout << typeid(Angle<390>::type).name() << "\n";

        return 0;
}

Output on Ideone

With Visual C++ 2010 Express, I can do static auto const = Modulus<N, 360>::value, but with MinGW gcc 4.7.2 (Nuwen distro) or Ideone (gcc 4.5.1) I have to either explicitly denote the type as static int const value = Modulus<N, 360>::value or I have to use auto with the full modular expression as static auto const value = N % 360;.

Question: Which compiler is correct acccording to the new C++11 Standard?

  • 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-06-12T23:01:43+00:00Added an answer on June 12, 2026 at 11:01 pm

    The code is valid. Visual C++ is right to accept it and gcc is wrong to reject it (for completeness, Clang 3.1 also accepts the code). The specification states that (C++11 7.1.6.4[dcl.spec.auto]/4):

    The auto type-specifier can also be used…in declaring a static data member with a brace-or-equal-initializer that appears within the member-specification of a class definition.

    Your value is a static data member. It has a brace-or-equal-initializer (that is the = Modulus<N, 360>::value part of the declaration), and the initializer appears within the member-specification of the class definition (i.e., it’s what mortals might call an “inline initializer”).

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

Sidebar

Related Questions

Consider the following simplified version of my code. I have a template class A
Consider the following simplified demonstration: Class X contain Class Y . Class Y has
Consider the following simplified objects and relationships: public class Job{ int JobId; String name;
Consider the following two Java files that contain a simplified version of my issue
Consider the following (simplified) code: enum eTestMode { TM_BASIC = 1, // 1 <<
Consider the following code sample that uses MEF to create an object of type
Let's consider the following simplified Resource hierarchy: public abstract class Resource { static public
I have an app that's about presenting fictional simplified cities. Please consider the following
Consider the following (simplified) situation: class Foo { private: int evenA; int evenB; int
Consider the following (simplified) example: abstract class Bar[T] { val f: PartialFunction[T, T] val

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.