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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:18:47+00:00 2026-06-12T10:18:47+00:00

So, I’m wishing to be able to have a static const compile time struct

  • 0

So, I’m wishing to be able to have a static const compile
time struct that holds some value based on a string by using
templates. I only desire up to four characters. I know that
the type of ‘abcd’ is int, and so is ‘ab’,’abc’, and although
‘a’ is of type char, it works out for a template<int v> struct

What I wish to do is take sizes of 2,3,4,5 of some const char, “abcd”
and have the same functionality as if they used ‘abcd’. Note that
I do not mean 1,2,3, or 4 because I expect the null terminator.

cout << typeid("abcd").name() << endl; tells me that the type for
this hard coded string is char const [5], which includes the null
terminator on the end.

I understand that I will need to twiddle the values as characters,
so they are represented as an integer.

I cannot use constexpr since VS10 does not support it (VS11 doesn’t either..)

So, for example with somewhere this template defined, and later the last line

template <int v> struct something {
    static const int value = v;
};

//Eventually in some method
cout << typeid(something<'abcd'>::value).name() << endl;

works just fine.

I’ve tried

template<char v[5]> struct something2 {
    static const int value = v[0];
}

template<char const v[5]> struct something2 {
    static const int value = v[0];
}

template<const char v[5]> struct something2 {
    static const int value = v[0];
}

All of them build individually, though when I throw in my test,

cout << typeid(something2<"abcd">::value).name() << endl;

I get

'something2' : invalid expression as a template argument for 'v'
'something2' : use of class template requires template argument list

Is this not feasible or am I misunderstanding something?

  • 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-12T10:18:48+00:00Added an answer on June 12, 2026 at 10:18 am

    14.1 lists the acceptable types of non-type template arguments:

    — integral or enumeration type,
    — pointer to object or pointer to function,
    — lvalue reference to object or lvalue reference to function,
    — pointer to member,

    Arrays don’t fit under any of these categories.

    14.3.2/1 lists categories of what’s permitted as template arguments and 14.3.2/2 goes on to say:

    Note: A string literal (2.14.5) does not satisfy the requirements of any of these categories and thus is not an acceptable template-argument.

    Therefore you cannot do what you’re trying to do.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
For some reason, after submitting a string like this Jack’s Spindle from a text
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.