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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T15:37:30+00:00 2026-05-31T15:37:30+00:00

I have a C++ template function which prints numbers. It works fine for everything,

  • 0

I have a C++ template function which prints numbers.

It works fine for everything, except when I’m working with data of type char.

I’d like char to be printed as int, but if I cast this explicitly in the template function, then I will lose precision on my float types.

I’d like to be able to say:

template<class T> bob(T a){
  cout<<if_char_make_int(a)<<endl;
}

But I’m not sure how to do this, or if it is possible.

Any thoughts?

  • 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-31T15:37:32+00:00Added an answer on May 31, 2026 at 3:37 pm
    template<class T> void bob(T a){
        std::cout
          << typename boost::mpl::if_<boost::is_same<char, T>, int, T>::type(a)
          << std::endl;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose I have a function which looks like this: template <class In, class In2>
I have the following template function which prints to cout: template <typename T> void
Imagine I have a template function like this: template<typename Iterator> void myfunc(Iterator a, typename
Is it possible to have a C++ template function which can access different fields
I have a Template Parser function which loads the raw html code of the
I have written a function template and an explicitly specialized templated function which simply
I have a load of php templates which uses a custom translate function __,
I have template function compare defined as below. #include<iostream> using namespace std; template<typename T>
Say I have a template function in namespace A. I also have another namespace
Let's assume we have a template function foo: template<class T> void foo(T arg) {

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.