0

Why does clang insist on choosing the 5 argument form of transform when there is a matching function signature using 4 arguments?

The compiler seems to think toupper is a binary operator, which is strange.

error message:

enum_days.cpp:18:5: error: no matching function for call to 'transform'
    transform(daystr.begin(), daystr.end(), daystr.begin(), toupper);
    ^~~~~~~~~
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/transform.h:26:1: note: candidate template ignored: couldn't infer template argument '_UnaryOperation'
transform(_InputIterator __first, _InputIterator __last, _OutputIterator __result, _UnaryOperation __op)
^
/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/v1/__algorithm/transform.h:36:1: note: candidate function template not viable: requires 5 arguments, but 4 were provided
transform(_InputIterator1 __first1, _InputIterator1 __last1, _InputIterator2 __first2,
^
1 error generated.

Code:

#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

typedef enum Days
{
    SUN, MON, TUE, WED, THU, FRI, SAT
} Days;

// map string value of day to the matching the Days ENUM constant
Days str2Days(string &daystr)
{
    Days dayout;

    transform(daystr.begin(), daystr.end(), daystr.begin(), toupper);

    if (daystr == "SUN") dayout = SUN; 
    else if (daystr =="MON") dayout = MON; 
    else if (daystr =="TUE") dayout = TUE; 
    else if (daystr =="WED") dayout = WED; 
    else if (daystr =="THU") dayout = THU; 
    else if (daystr =="FRI") dayout = FRI; 
    else if (daystr =="SAT") dayout = SAT; 
    else {
        cout << "Input string for day is incorrect.\n";
        exit(-1);
    }

    return dayout;
}

It's as if the compiler doesn't seem to interpret a string as an array of chars.

Lewis Levin
  • 85
  • 11

0 Answers0