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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:31:30+00:00 2026-06-13T10:31:30+00:00

#include <iostream> #include <array> using namespace std; constexpr int N = 10; constexpr int

  • 0
#include <iostream>
#include <array>
using namespace std;

constexpr int N = 10;
constexpr int f(int x) { return x*2; }

typedef array<int, N> A;

template<int... i> struct F { constexpr A f() { return A{{ f(i)... }}; } };

template<class X, class Y> struct C;
template<int... i, int... j>
struct C<F<i...>, F<j...>> : F<i..., (sizeof...(i)+j)...> {};

template<int n> struct S : C<S<n/2>, S<n-n/2>> {}; // <--- HERE
template<> struct S<1> : F<0> {};

constexpr auto X = S<N>::f();

int main()
{
        cout << X[3] << endl;
}

I’m getting:

test.cpp:15:24: error: invalid use of incomplete type ‘struct C<S<5>, S<5> >’

I suspect this is because the definition of S is using itself as a base class. (Correct?)

What is the best way to fix this?

Update:

Here is the fixed version:

#include <iostream>
#include <array>
using namespace std;

constexpr int N = 10;
constexpr int f(int x) { return x*2; }

typedef array<int, N> A;

template<int... i> struct F { static constexpr A f() { return A{{ ::f(i)... }}; } };

template<class A, class B> struct C {};
template<int... i, int... j> struct C<F<i...>, F<j...>> : F<i..., (sizeof...(i)+j)...>
{
        using T = F<i..., (sizeof...(i)+j)...>;
};

template<int n> struct S : C<typename S<n/2>::T, typename S<n-n/2>::T> {};
template<> struct S<1> : F<0> { using T = F<0>; };

constexpr auto X = S<N>::f();

int main()
{
        cout << X[3] << endl;
}
  • 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-13T10:31:31+00:00Added an answer on June 13, 2026 at 10:31 am

    Define C instead of just declaring it.

    template<class X, class Y> struct C {};
    

    In the place you use it the partial specialization does not match and
    the primary template is instantiated, which is just a declaration.

    You may wonder why that specialization is not considered: specializations don’t consider conversions, but just the static type. That’s why they are so treacherously incompatible with inheritance.

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

Sidebar

Related Questions

Consider this code: #include <iostream> using namespace std; typedef int array[12]; array sample; array
here is my code for implementing HeapTree #include<iostream> #include<assert.h> using namespace std; template <class
#include <iostream> #include <iomanip> using namespace std; int main() { char array[10]; for(int i
#include <iostream> using namespace std; class Array { friend ostream &operator<<( ostream &, const
Consider the following code: #include <iostream> using namespace std; class Test { static int
I have the following code: #include <iostream> using namespace std; struct stud{ int roll;
Here is my code #include<iostream> #include<fstream> using namespace std; int main() { int* arr
when i compile this code #include <iostream> #include<algorithm> using namespace std; template <class T>
I have convex hull algorithm: #include <cstdlib> #include <iostream> using namespace std; typedef int
Here is my code: #include <iostream> #include <stdio.h> #include <stdlib.h> using namespace std; struct

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.