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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:32:50+00:00 2026-06-03T08:32:50+00:00

I have a problem in my application where I’d like to assert that a

  • 0

I have a problem in my application where I’d like to assert that a function application would be rejected by the compiler. Is there a way to check this with SFINAE?

For example, assume that I’d like to validate that std::transform to a const range is illegal. Here’s what I have so far:

#include <algorithm>
#include <functional>
#include <iostream>

namespace ns
{

using std::transform;

template<typename Iterator1, typename Iterator2, typename UnaryFunction>
  struct valid_transform
{
  static Iterator1 first1, last1;
  static Iterator2 first2;
  static UnaryFunction f;

  typedef Iterator2                   yes_type;
  typedef struct {yes_type array[2];} no_type;

  static no_type transform(...);

  static bool const value = sizeof(transform(first1, last1, first2, f)) == sizeof(yes_type);
};

}

int main()
{
  typedef int *iter1;
  typedef const int *iter2;
  typedef std::negate<int> func;

  std::cout << "valid transform compiles: " << ns::valid_transform<iter1,iter1,func>::value << std::endl;

  std::cout << "invalid transform compiles: " << ns::valid_transform<iter1,iter2,func>::value << std::endl;

  return 0;
}

Unfortunately, my trait rejects both the legal and the illegal cases. The result:

$ g++ valid_transform.cpp 
$ ./a.out 
valid transform compiles: 0
invalid transform compiles: 0
  • 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-03T08:32:51+00:00Added an answer on June 3, 2026 at 8:32 am

    Your question is similar to SFINAE + sizeof = detect if expression compiles.

    Summary of that answer: sizeof evaluates the type of the expression passed to it, including instantiating a function template, but it does not generate a function call. This is the reason behind Lol4t0’s observations that sizeof(std::transform(iter1(), iter1(), iter2(), func())) compiles even if std::transform(iter1(), iter1(), iter2(), func()) does not.

    Your concrete problem can be solved by evaluating the template from Lol4t0’s answer for any output range that is to be supplied to std::transform. However, the general problem of verifying in a template that a function call will compile appears to be impossible to be solved with the sizeof + SFINAE trick. (it would require a compile-time expression that is derivable from a run-time function call).

    You might want to try ConceptGCC to see if this allows you to express the requisite compile-time checking in a more convenient way.

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

Sidebar

Related Questions

I have problem with my application. I have table report, there are 2 column
I have this problem in my ASP.NET application where I'm seeing some of my
I have this problem in my application: Step 1 - create an file (xml)
I have problem with my Android application. I need an application that will send
I have a problem with an application I'm currently developing. In this program I
I have problem, when converting Windows application from .NET2.0 to .NET3.5. I do this
I have a problem concerning good application design that has been keeping me up
i have a problem with my application tha some times return this error in
A have a problem with PHP application, that I'm working on. Main page which
I have this problem: My web application has a form where the users can

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.