関数内関数イディオム

cppll:11286にあった関数内関数イディオムで、昨日の関数オーバーロード問題を解決をしてみる

#include <string>
#include <vector>
#include <algorithm>

using namespace std;

double stod(const string& s) { return atof(s.c_str()); }
double stod(const wstring& s) { return _wtof(s.c_str()); }

int main()
{
    struct local {
        static double stod(const string& s) { return ::stod(s); }
    };

    string ar[] = {"3.14", "1.23", "5.67"};

    vector<double> v;
    transform(ar, ar + 3, back_inserter(v), &local::stod); // OK

    return 0;
}