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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:23:21+00:00 2026-06-09T07:23:21+00:00

Suppose you attempt to do the following: template</* args */> typename std::enable_if< /*conditional*/ ,

  • 0

Suppose you attempt to do the following:

template</* args */>
typename std::enable_if< /*conditional*/ , /*type*/ >::type
static auto hope( /*args*/) -> decltype( /*return expr*/ )
{
}

Is it possible to combine conditional inclusion/overloading (std::enable_if) with trailing-return-type (auto ... -> decltype())?

I would not be interesting in solutions using the preprocessor. I can always do things like

#define RET(t) --> decltype(t) { return t; }

and extend it to take also the whole conditional. Instead I am interested if the language supports it without using another trait for the return type, i.e. ReturnType<A,B>::type_t or whatever is used in the function body.

  • 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-09T07:23:22+00:00Added an answer on June 9, 2026 at 7:23 am

    The trailing-return-type isn’t much different from the normal return type, except that it’s specified after the parameter list and cv-/ref-qualifiers. Also, it doesn’t necessarily need decltype, a normal type is fine too:

    auto answer() -> int{ return 42; }
    

    So by now you should see what the answer to your question is:

    template<class T>
    using Apply = typename T::type; // I don't like to spell this out
    
    template</* args */>
    static auto hope( /*args*/)
        -> Apply<std::enable_if</* condition */, decltype( /*return expr*/ )>>
    {
    }
    

    Though I personally prefer using just decltype and expression SFINAE, as long as the condition can be expressed as an expression (e.g., can you invoke a function on an object of a certain type):

    template<class T>
    static auto hope(T const& arg)
      -> decltype(arg.foo(), void())
    {
      // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Suppose my attempt to write a pickle object out to disk is incomplete due
Suppose I have a static method of my class that returns an object of
Suppose I have the following three tables expressing a relationship where posts are given
I am having difficulty with the following code which is inside a static method
Suppose I have the following class hierarchy: class A { int foo; virtual ~A()
Suppose I do the following: I create a MySQL database, and populate it with
I'm following a number of different tutorials in an attempt to make a generic
Suppose I have the following array $diff . a, a, a, a, b, b,
suppose i have a .on() function wherein i select multiple ids $(#i, #am, #your,
Suppose I have a large list of words. For an example: >>> with open('/usr/share/dict/words')

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.