function template throws errors on <

(g++)error: expected initializer before '<' token
1
2
3
4
5
6
namespace str {
    template<class S>    
    S str::localestringlower<S>(S s) {
        ...
    }
}


how would I fix this? nothing I try works.
Last edited on
if I don't specify str::, my own version of find will conflict with the one in std::string. it should not.
1
2
3
4
5
6
7
8
9
namespace str {

    template < class S >
    S localestringlower(S s) {

        // str::find(...) // use qualified name for find
        // ...
    }
}
thanks for the idea. I think the c++ std lib at least in gcc needs fixing though. it's only find and compare that it conflicts with. or so I thought.
interesting. I did not want to mangle my own libraries because of someone else's bug.

the error message certainly doesn't fit the problem, does it?

is there some way to use a macro to do this so I can take out the workaround at the top of the code?

maybe like
#define STRFUNC(fn) fn123
Last edited on
This is ambiguous, and the error diagnostic points out the ambiguity:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <string>
#include <algorithm>

namespace my
{
    template < typename I, typename T > void find( I, I, T ) ;

    void foo( std::string str )
    {
        // ambiguous: 
        //    normal unqualified look up finds my::find
        //    argument-dependent lookup finds std::find
        //    http://en.cppreference.com/w/cpp/language/adl
        find( str.begin(), str.end(), 89 ) ;
    }
}


main.cpp: In function 'void my::foo(std::__cxx11::string)':
main.cpp:14:42: error: call of overloaded 'find(...)' is ambiguous
         find( str.begin(), str.end(), 89 ) ;
                                          ^
main.cpp:6:46: note: candidate: void my::find(I, I, T) [with I = __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >; T = int]
     template < typename I, typename T > void find( I, I, T ) ;
                                              ^~~~
In file included from /usr/local/include/c++/6.1.0/algorithm:62:0,
                 from main.cpp:2:
/usr/local/include/c++/6.1.0/bits/stl_algo.h:3791:5: note: candidate: _IIter std::find(_IIter, _IIter, const _Tp&) [with _IIter = __gnu_cxx::__normal_iterator<char*, std::__cxx11::basic_string<char> >; _Tp = int]
     find(_InputIterator __first, _InputIterator __last,
     ^~~~

http://coliru.stacked-crooked.com/a/6b0c665d1428717b
Topic archived. No new replies allowed.