Member function pointer issue with standard library methods

前端 未结 1 1999
梦毁少年i
梦毁少年i 2021-01-12 23:40

This question is spawned from
Passing a member function pointer to an overloaded class method into a template function.
You need not read that to understand this que

1条回答
  •  醉酒成梦
    2021-01-13 00:42

    The problem isn't with the insert functions you showed in MySet. The problem is with one of the ones you omitted. Specifically:

    template< class InputIt >
    void insert( InputIt first, InputIt last );
    

    From [temp.deduct.call]:

    When P is a function type, pointer to function type, or pointer to member function type:
    — If the argument is an overload set containing one or more function templates, the parameter is treated as a non-deduced context.

    Since &std::set::insert is precisely such an overload set, the parameter is a non-deduced context and cannot be resolved. Your example of MySet does not contain a function template overload for insert, which is why it works fine. If you add one, you'll see that it will also fail to compile.

    0 讨论(0)
提交回复
热议问题