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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T15:10:35+00:00 2026-06-18T15:10:35+00:00

I am getting a SFINAE error with the following code as it will not

  • 0

I am getting a SFINAE error with the following code as it will not use the template. I am trying to perfect forward the args in as the result. Any ideas anyone.

#include <iostream>

#include "constants.h"


namespace perfectforwarding
{
    template<class T, class U>
    constexpr auto maximum(T&& a, U&& b) -> decltype( (a > b) ? std::forward(a) : std::forward(b))
    {
        return (a > b) ? std::forward(a) : std::forward(b);
    }
}



int main(int argc, const char * argv[])
{

    std::cout << "Created count is: " << created_count << std::endl;

    auto const result = perfectforwarding::maximum(5,6.0);

    std::cout << "The maximum of 5 and 6: " << result << std::endl;
    return 0;
}

Blair

  • 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-18T15:10:36+00:00Added an answer on June 18, 2026 at 3:10 pm

    std::forward is a template, and you need to provide the type argument explicitly if you want it to work properly. This is how your maximum function template should be rewritten:

    template<class T, class U>
    constexpr auto maximum(T&& a, U&& b) -> 
        decltype( (a > b) ? std::forward<T>(a) : std::forward<U>(b))
    {
        return (a > b) ? std::forward<T>(a) : std::forward<U>(b);
    }
    

    This is how the std::forward utility is defined:

    template<class T> 
    T&& forward(typename remove_reference<T>::type& a) noexcept
    {
        return static_cast<S&&>(a);
    }
    

    The expression typename remove_reference<T>::type makes this a non-deduced context, which explains why type deduction fails if you do not explicitly provide the type argument T.

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

Sidebar

Related Questions

Getting the following error/exception while trying to compile my maven based web application... can
Getting the following error while trying to do checkout Build errors # [11:27:20]Failed to
Getting 401 errors when trying to use ASP.NET back end in load balanced environment
Getting 'Dispatcher has no subscribers' error while trying to post message to a channel
Getting this weird LINQ error. title = System.Linq.Enumerable+WhereSelectEnumerableIterator`2[System.Xml.Linq.XElement,System.String Here is the code I have:
Getting a strange error when trying to insert data into an Access database using
Getting the following error: "Warning: Cannot modify header information - headers already sent by
Getting error with Could not find endpoint element with name 'CaseJacketPort' and contract 'GrandJuryService.CaseJacket'
Getting this message inside gdb. I know its not an error or anything. I
getting a no method error while using clearance for authentication, i was trying to

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.