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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T00:15:26+00:00 2026-06-07T00:15:26+00:00

In a template function that looks like this: template<typename T> constexpr T foo(T a,

  • 0

In a template function that looks like this:

template<typename T> constexpr T foo(T a, T b) { return /*recursive call*/; }

I am getting a warning about comparing signed vs unsigned (due to comparing against sizeof) which I’d like to eliminate.

Conceptually, one would need something like this:

template<typename T> constexpr T foo(T a, unsigned T b) { ... }
    or
template<typename T> constexpr T foo(T a, std::make_unsigned<T>::type b) { ... }

Unluckily, the first version is not valid C++, and the second version breaks the build because T is not a qualified type when the compiler sees make_unsigned.

Is there is a solution for this that actually works?

(NB: Somehow related to / almost same as Get the signed/unsigned variant of an integer template parameter without explicit traits, though function rather than class (so no typedefs), traits or any feature of C++11 explicitly welcome, and working solution (i.e. not make_unsigned<T>) preferred.)

  • 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-07T00:15:28+00:00Added an answer on June 7, 2026 at 12:15 am

    You forgot a ‘typename’

    template<typename T>
    constexpr T foo(T a, typename std::make_unsigned<T>::type b) { ... }
    

    In C++14 you should be able to write

    template<typename T>
    constexpr T foo(T a, std::make_unsigned_t<T> b) { ... }
    

    Or you can implement this yourself in C++11:

    template<typename T>
    using make_unsigned_t = typename std::make_unsigned<T>::type;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a (free) function template that looks like this template <typename T> T
I've got a compile-time recursive type that looks somewhat like this: template <typename DataType,
I have a template class in C++ that looks like this: template <typename T,
I want to have a function with interface like this: template<typename T, typename R>
Having trouble inheriting from a template class. Looks something like this: template<typename type> class
I have an ajax request that looks like this, $(#frmProducts).submit(function(){ var dataSet = $(#frmProducts).serialize();
background: url({{ MEDIA_URL }}/bg.jpg); That does not work, because this Django template function only
I have a subset of a pointer class that look like: template <typename T>
I have a string that looks something like this: {{imagename.jpg|left|The caption for this image.
I have data that looks like this: token eps rank # first line names

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.