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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:25:34+00:00 2026-05-14T05:25:34+00:00

I am trying to specialize template the following way: template<size_t _1,size_t _2> // workaround:

  • 0

I am trying to specialize template the following way:

template<size_t _1,size_t _2> // workaround: bool consecutive = (_1 == _2 - 1)>
struct integral_index_ {};
...
template<size_t _1>
struct integral_index_<_1, _1 + 1> { // cannot do arithmetic?
//struct integral_index_<_1, _2, true> { workaround
};

however I get compiler message error

the template argument list of the partial specialization includes a non
-type argument whose type depends on a template parameter.

what do my doing wrong?
thanks

I put workaround in comments. Apparently I cannot do arithmetic in template specialization? seems counterintuitive.

here is my final solution in the problem to be solved. Basically, consecutive index requires one multiplication only.

130 template<size_t _1,size_t _2, bool consecutive = (_1 == _2 - 1)>
131 struct integral_index_ {
132     template<typename T, typename U>
133     __device__
134     static T eval(const T (&N)[4], const U &index) {
135         T j = index/N[_1];
136         return ((index - j*N[_1])*range<0,_1>::multiply(N) +
137                 j*range<0,_2>::multiply(N));
138     }
139 };
140
141 template<size_t _1,size_t _2>
142 struct integral_index_<_1, _2, true> {
143     template<typename T, typename U>
144     __device__
145     static T eval(const T (&N)[4], const U &index) {
146         return index*range<0,_1>::multiply(N);
147     }
148 };
149
150 template<size_t _1,size_t _2, typename T, typename U>
151 __device__
152 T integral_index(const T (&N)[4], const U &index) {
153     return integral_index_<_1,_2>::eval(N, index);
154 }
  • 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-14T05:25:34+00:00Added an answer on May 14, 2026 at 5:25 am

    I am posting my solution is suggested by GMan

    130 template<size_t _1,size_t _2, bool consecutive = (_1 == _2 - 1)>
    131 struct integral_index_ {
    132     template<typename T, typename U>
    133     __device__
    134     static T eval(const T (&N)[4], const U &index) {
    135         T j = index/N[_1];
    136         return ((index - j*N[_1])*range<0,_1>::multiply(N) +
    137                 j*range<0,_2>::multiply(N));
    138     }
    139 };
    140
    141 template<size_t _1,size_t _2>
    142 struct integral_index_<_1, _2, true> {
    143     template<typename T, typename U>
    144     __device__
    145     static T eval(const T (&N)[4], const U &index) {
    146         return index*range<0,_1>::multiply(N);
    147     }
    148 };
    149
    150 template<size_t _1,size_t _2, typename T, typename U>
    151 __device__
    152 T integral_index(const T (&N)[4], const U &index) {
    153     return integral_index_<_1,_2>::eval(N, index);
    154 }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following primary template: template<size_t pos, size_t lev> struct Sol; and I
I'm trying to partially specialize a trait for arrays of non-chars: template<typename T> struct
I'm trying to expose the following c++ function to python using boost.python: template <typename
I'm trying to specialize a template method of non-template class in its subclass: //
Is there an elegant way to specialize a template based on one of its
I'm trying to specialize just one method of a class template . The accepted
I'm trying to write code that uses a member typedef of a template argument,
I've been trying to implement a function that needs partial template specializations and fallen
Please, see what I am trying to do: #include <iostream> namespace first { template
I am trying to specialize some utility code on const member functions, but have

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.