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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:31:14+00:00 2026-06-15T09:31:14+00:00

Simplified version class C { public: static constexpr std::array<C, 2> foo {{1_C, 2_C}}; int

  • 0

Simplified version

class C {
 public:
 static constexpr std::array<C, 2> foo {{"1"_C, "2"_C}};
 int x;
 constexpr C(char c) { x=c; }
}
constexpr C operator"" _C(const char * str, size_t n) { return C(*str); }

This doesn’t fly, because the literals are not understood at the line where the array is defined. But the free literal function can’t be moved earlier because then C isn’t known.

Is there a solution to this Gordian knot that doesn’t involve adding variadic templates or something horrid like that into the code?

  • 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-15T09:31:16+00:00Added an answer on June 15, 2026 at 9:31 am

    The problem doesn’t really lie with user-defined literals, but with the fact that std::array requires complete types (or really, any constexpr initialization does). The following code will also fail to compile:

    #include <array>
    
    class C {
    public:
     static constexpr std::array<C, 2> foo {{C('1'), C('2')}};
     int x;
     constexpr C(char c) : x(c) {} // please use a mem-initializer-list
    };
    

    With errors similar to (Clang 3.3 SVN here):

    /usr/include/c++/v1/array:136:16: error: field has incomplete type 'value_type'
          (aka 'C')
        value_type __elems_[_Size > 0 ? _Size : 1];
                   ^
    t.cpp:5:36: note: in instantiation of template class 'std::__1::array'
          requested here
     static constexpr std::array<C, 2> foo {{C('1'), C('2')}};
                                       ^
    t.cpp:3:7: note: definition of 'C' is not complete until the closing '}'
    class C {
          ^
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's a simplified version of my class: public abstract class Task { private static
I have a decorated function (simplified version): class Memoize: def __init__(self, function): self.function =
Here is simplified version of my requirement I have a java class say Processor
Here is a simplified version of one of my models: class ImportRule(models.Model): feed =
Here is a simplified version of what I have (not working): prog.h: ... const
I have class B that has class A, this is simplified version of class
Here is a much simplified version of what I am trying to do static
I got the following code for my object (short version) : public class PluginClass
I have a few classes something like this: public class Weapon { public static
This is a simplified version of a class that I have in my project.

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.