Generic lambda vs generic function give different behaviourWhat is a lambda (function)?What is the difference between #include <filename> and #include “filename”?What are the differences between a pointer variable and a reference variable in C++?What is the difference between a 'closure' and a 'lambda'?Why are Python lambdas useful?Distinct() with lambda?list comprehension vs. lambda + filterWhat is a lambda expression in C++11?Calling `this` member function from generic lambda - clang vs gccConstructing std::function argument from lambda

Will it be accepted, if there is no ''Main Character" stereotype?

How does it work when somebody invests in my business?

How will losing mobility of one hand affect my career as a programmer?

Was the picture area of a CRT a parallelogram (instead of a true rectangle)?

Is there any reason not to eat food that's been dropped on the surface of the moon?

At which point does a character regain all their Hit Dice?

How to verify if g is a generator for p?

Mapping a list into a phase plot

Where in the Bible does the greeting ("Dominus Vobiscum") used at Mass come from?

How does residential electricity work?

Is a roofing delivery truck likely to crack my driveway slab?

Why does John Bercow say “unlock” after reading out the results of a vote?

Finding all intervals that match predicate in vector

The plural of 'stomach"

What's the purpose of "true" in bash "if sudo true; then"

Coordinate position not precise

Generic lambda vs generic function give different behaviour

What's a natural way to say that someone works somewhere (for a job)?

apt-get update is failing in debian

Your magic is very sketchy

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?

What is the opposite of 'gravitas'?

Efficiently merge handle parallel feature branches in SFDX

Is exact Kanji stroke length important?



Generic lambda vs generic function give different behaviour


What is a lambda (function)?What is the difference between #include <filename> and #include “filename”?What are the differences between a pointer variable and a reference variable in C++?What is the difference between a 'closure' and a 'lambda'?Why are Python lambdas useful?Distinct() with lambda?list comprehension vs. lambda + filterWhat is a lambda expression in C++11?Calling `this` member function from generic lambda - clang vs gccConstructing std::function argument from lambda













8















Take following code as an example



#include <algorithm>

namespace baz
template<class T>
void sort(T&&)


namespace boot
const auto sort = [](auto &&);


void foo ()
using namespace std;
using namespace baz;
sort(1);


void bar()
using namespace std;
using namespace boot;
sort(1);



I expected that since foo compiled, then bar shall compile as well. To my surprise, the foo compiles correctly and bar has problem with ambiguous call to sort function. Am I doing something illegal here or this is proper way compiler should behave? If so, why is it so different. I though generic lambda can be treated as syntactic sugar for generic function.



live example










share|improve this question



















  • 4





    Lambdas do not participate in ADL

    – Guillaume Racicot
    2 hours ago






  • 5





    This isn't ADL. An int argument doesn't come from any namespace.

    – chris
    2 hours ago






  • 2





    Should this really be ambiguous, though? std::sort() doesn't take 1 parameter as input, it takes at least 2, so why is the compiler even considering it as a candidate for a call that passes only 1 parameter value?

    – Remy Lebeau
    1 hour ago












  • There must be something about the extra layer of indirection that the lambda introduces. With the first example, the call is made to ::baz::sort, but in the second example, it would have to find ::boot::mystery_lambda_type::operator(). That extra step might be what causes std::sort to be considered first. I don't have the standard in front of me so can't be sure about this.

    – alter igel
    1 hour ago















8















Take following code as an example



#include <algorithm>

namespace baz
template<class T>
void sort(T&&)


namespace boot
const auto sort = [](auto &&);


void foo ()
using namespace std;
using namespace baz;
sort(1);


void bar()
using namespace std;
using namespace boot;
sort(1);



I expected that since foo compiled, then bar shall compile as well. To my surprise, the foo compiles correctly and bar has problem with ambiguous call to sort function. Am I doing something illegal here or this is proper way compiler should behave? If so, why is it so different. I though generic lambda can be treated as syntactic sugar for generic function.



live example










share|improve this question



















  • 4





    Lambdas do not participate in ADL

    – Guillaume Racicot
    2 hours ago






  • 5





    This isn't ADL. An int argument doesn't come from any namespace.

    – chris
    2 hours ago






  • 2





    Should this really be ambiguous, though? std::sort() doesn't take 1 parameter as input, it takes at least 2, so why is the compiler even considering it as a candidate for a call that passes only 1 parameter value?

    – Remy Lebeau
    1 hour ago












  • There must be something about the extra layer of indirection that the lambda introduces. With the first example, the call is made to ::baz::sort, but in the second example, it would have to find ::boot::mystery_lambda_type::operator(). That extra step might be what causes std::sort to be considered first. I don't have the standard in front of me so can't be sure about this.

    – alter igel
    1 hour ago













8












8








8


1






Take following code as an example



#include <algorithm>

namespace baz
template<class T>
void sort(T&&)


namespace boot
const auto sort = [](auto &&);


void foo ()
using namespace std;
using namespace baz;
sort(1);


void bar()
using namespace std;
using namespace boot;
sort(1);



I expected that since foo compiled, then bar shall compile as well. To my surprise, the foo compiles correctly and bar has problem with ambiguous call to sort function. Am I doing something illegal here or this is proper way compiler should behave? If so, why is it so different. I though generic lambda can be treated as syntactic sugar for generic function.



live example










share|improve this question
















Take following code as an example



#include <algorithm>

namespace baz
template<class T>
void sort(T&&)


namespace boot
const auto sort = [](auto &&);


void foo ()
using namespace std;
using namespace baz;
sort(1);


void bar()
using namespace std;
using namespace boot;
sort(1);



I expected that since foo compiled, then bar shall compile as well. To my surprise, the foo compiles correctly and bar has problem with ambiguous call to sort function. Am I doing something illegal here or this is proper way compiler should behave? If so, why is it so different. I though generic lambda can be treated as syntactic sugar for generic function.



live example







c++ lambda c++14






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 hours ago







bartop

















asked 2 hours ago









bartopbartop

3,2281030




3,2281030







  • 4





    Lambdas do not participate in ADL

    – Guillaume Racicot
    2 hours ago






  • 5





    This isn't ADL. An int argument doesn't come from any namespace.

    – chris
    2 hours ago






  • 2





    Should this really be ambiguous, though? std::sort() doesn't take 1 parameter as input, it takes at least 2, so why is the compiler even considering it as a candidate for a call that passes only 1 parameter value?

    – Remy Lebeau
    1 hour ago












  • There must be something about the extra layer of indirection that the lambda introduces. With the first example, the call is made to ::baz::sort, but in the second example, it would have to find ::boot::mystery_lambda_type::operator(). That extra step might be what causes std::sort to be considered first. I don't have the standard in front of me so can't be sure about this.

    – alter igel
    1 hour ago












  • 4





    Lambdas do not participate in ADL

    – Guillaume Racicot
    2 hours ago






  • 5





    This isn't ADL. An int argument doesn't come from any namespace.

    – chris
    2 hours ago






  • 2





    Should this really be ambiguous, though? std::sort() doesn't take 1 parameter as input, it takes at least 2, so why is the compiler even considering it as a candidate for a call that passes only 1 parameter value?

    – Remy Lebeau
    1 hour ago












  • There must be something about the extra layer of indirection that the lambda introduces. With the first example, the call is made to ::baz::sort, but in the second example, it would have to find ::boot::mystery_lambda_type::operator(). That extra step might be what causes std::sort to be considered first. I don't have the standard in front of me so can't be sure about this.

    – alter igel
    1 hour ago







4




4





Lambdas do not participate in ADL

– Guillaume Racicot
2 hours ago





Lambdas do not participate in ADL

– Guillaume Racicot
2 hours ago




5




5





This isn't ADL. An int argument doesn't come from any namespace.

– chris
2 hours ago





This isn't ADL. An int argument doesn't come from any namespace.

– chris
2 hours ago




2




2





Should this really be ambiguous, though? std::sort() doesn't take 1 parameter as input, it takes at least 2, so why is the compiler even considering it as a candidate for a call that passes only 1 parameter value?

– Remy Lebeau
1 hour ago






Should this really be ambiguous, though? std::sort() doesn't take 1 parameter as input, it takes at least 2, so why is the compiler even considering it as a candidate for a call that passes only 1 parameter value?

– Remy Lebeau
1 hour ago














There must be something about the extra layer of indirection that the lambda introduces. With the first example, the call is made to ::baz::sort, but in the second example, it would have to find ::boot::mystery_lambda_type::operator(). That extra step might be what causes std::sort to be considered first. I don't have the standard in front of me so can't be sure about this.

– alter igel
1 hour ago





There must be something about the extra layer of indirection that the lambda introduces. With the first example, the call is made to ::baz::sort, but in the second example, it would have to find ::boot::mystery_lambda_type::operator(). That extra step might be what causes std::sort to be considered first. I don't have the standard in front of me so can't be sure about this.

– alter igel
1 hour ago












2 Answers
2






active

oldest

votes


















5














Lambdas are no different than regular functors or even plain function pointers in this regard. Overload resolution is only considering as candidates actual functions that are named sort. In other words, overload resolution is not going to consider literally anything that has a function call operator. Only true functions.



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

namespace baz

template<class T>
void sort(T&&)


namespace boot
const auto sort = [](auto &&);


namespace booot
struct sort_functor

template<class T>
void operator()(T&&)const;
;

constexpr sort_functor sort;


namespace boooot

void sort_func(int)

constexpr auto sort = &sort_func;


void foo ()
using namespace std;
using namespace baz;
sort(1);


void bar()
using namespace std;
using namespace boot;
sort(1);



void baar()
using namespace std;
using namespace booot;
sort(1); // still an error



void baaar()
using namespace std;
using namespace boooot;
sort(1); // still the exact same error



UPDATE: To answer Michael Kenzel's question below. Consider the function baar:



void baar()
using namespace std;
using namespace booot;
// sort(1); is syntatic sugar for:
sort.operator()(1);



Consider the expression sort.operator()(1). It actually consists of two operators. First the binary . operator is applied with operands sort and operator(). The result of this sub-expression is a true function type, and it is a prvalue. Although indeed it is a true function type, it is an rvalue and so it has no name. It is most definitely not named sort, so it cannot be considered for overload resolution of functions named sort.



The sole purpose of the prvalue function type resulting from expressions like:



some_instance.some_method
some_instance_ptr->some_method
(some_instance.*(&some_type::some_method))
(some_instance_ptr->*(&some_type::some_method))


is to have 1) be a true function type and therefore 2) have a function call operator.



So when a type has a user defined call operator and uses the sugary syntax, the call operator is not really being applied to the object, it is being applied to a true function type prvalue resulting from an expression like above.






share|improve this answer










New contributor




Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • Sounds logical to me, +1.

    – Paul Sanders
    1 hour ago











  • I'm not sure I understand this answer. If overload resolution does not consider objects with an overloaded function call operator, then a) how is it possible for overloading of the function call operator to function at all, and b) how come the error occur in cases where there is an object in the overload set!?

    – Michael Kenzel
    1 hour ago












  • booooot!!!!!!

    – Yakk - Adam Nevraumont
    51 mins ago


















1














The problem here is not that the call to sort is ambiguous, but that the name sort is ambiguous. Name lookup happens before overload resolution.



I believe the relevant section is [basic.lookup]/1, specifically




[…] The declarations found by name lookup shall either all denote the same entity or shall all denote functions or function templates; in the latter case, the declarations are said to form a set of overloaded functions ([over.load]). […]




In your case, the name sort denotes both, the object boot::sort as well as the set of overloaded functions std::sort. Therefore, name lookup fails.



Your code is not different from if you had written, for example



namespace baz 
int a;


namespace boot
int a;


void foo()
using namespace baz;
using namespace boot;
a = 42; // error: reference to 'a' is ambiguous



Try it out here, note how the error message is the same as in your case, specifically referring to the name itself being ambiguous rather than the function call.






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function ()
    StackExchange.using("externalEditor", function ()
    StackExchange.using("snippets", function ()
    StackExchange.snippets.init();
    );
    );
    , "code-snippets");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "1"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367269%2fgeneric-lambda-vs-generic-function-give-different-behaviour%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    5














    Lambdas are no different than regular functors or even plain function pointers in this regard. Overload resolution is only considering as candidates actual functions that are named sort. In other words, overload resolution is not going to consider literally anything that has a function call operator. Only true functions.



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

    namespace baz

    template<class T>
    void sort(T&&)


    namespace boot
    const auto sort = [](auto &&);


    namespace booot
    struct sort_functor

    template<class T>
    void operator()(T&&)const;
    ;

    constexpr sort_functor sort;


    namespace boooot

    void sort_func(int)

    constexpr auto sort = &sort_func;


    void foo ()
    using namespace std;
    using namespace baz;
    sort(1);


    void bar()
    using namespace std;
    using namespace boot;
    sort(1);



    void baar()
    using namespace std;
    using namespace booot;
    sort(1); // still an error



    void baaar()
    using namespace std;
    using namespace boooot;
    sort(1); // still the exact same error



    UPDATE: To answer Michael Kenzel's question below. Consider the function baar:



    void baar()
    using namespace std;
    using namespace booot;
    // sort(1); is syntatic sugar for:
    sort.operator()(1);



    Consider the expression sort.operator()(1). It actually consists of two operators. First the binary . operator is applied with operands sort and operator(). The result of this sub-expression is a true function type, and it is a prvalue. Although indeed it is a true function type, it is an rvalue and so it has no name. It is most definitely not named sort, so it cannot be considered for overload resolution of functions named sort.



    The sole purpose of the prvalue function type resulting from expressions like:



    some_instance.some_method
    some_instance_ptr->some_method
    (some_instance.*(&some_type::some_method))
    (some_instance_ptr->*(&some_type::some_method))


    is to have 1) be a true function type and therefore 2) have a function call operator.



    So when a type has a user defined call operator and uses the sugary syntax, the call operator is not really being applied to the object, it is being applied to a true function type prvalue resulting from an expression like above.






    share|improve this answer










    New contributor




    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















    • Sounds logical to me, +1.

      – Paul Sanders
      1 hour ago











    • I'm not sure I understand this answer. If overload resolution does not consider objects with an overloaded function call operator, then a) how is it possible for overloading of the function call operator to function at all, and b) how come the error occur in cases where there is an object in the overload set!?

      – Michael Kenzel
      1 hour ago












    • booooot!!!!!!

      – Yakk - Adam Nevraumont
      51 mins ago















    5














    Lambdas are no different than regular functors or even plain function pointers in this regard. Overload resolution is only considering as candidates actual functions that are named sort. In other words, overload resolution is not going to consider literally anything that has a function call operator. Only true functions.



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

    namespace baz

    template<class T>
    void sort(T&&)


    namespace boot
    const auto sort = [](auto &&);


    namespace booot
    struct sort_functor

    template<class T>
    void operator()(T&&)const;
    ;

    constexpr sort_functor sort;


    namespace boooot

    void sort_func(int)

    constexpr auto sort = &sort_func;


    void foo ()
    using namespace std;
    using namespace baz;
    sort(1);


    void bar()
    using namespace std;
    using namespace boot;
    sort(1);



    void baar()
    using namespace std;
    using namespace booot;
    sort(1); // still an error



    void baaar()
    using namespace std;
    using namespace boooot;
    sort(1); // still the exact same error



    UPDATE: To answer Michael Kenzel's question below. Consider the function baar:



    void baar()
    using namespace std;
    using namespace booot;
    // sort(1); is syntatic sugar for:
    sort.operator()(1);



    Consider the expression sort.operator()(1). It actually consists of two operators. First the binary . operator is applied with operands sort and operator(). The result of this sub-expression is a true function type, and it is a prvalue. Although indeed it is a true function type, it is an rvalue and so it has no name. It is most definitely not named sort, so it cannot be considered for overload resolution of functions named sort.



    The sole purpose of the prvalue function type resulting from expressions like:



    some_instance.some_method
    some_instance_ptr->some_method
    (some_instance.*(&some_type::some_method))
    (some_instance_ptr->*(&some_type::some_method))


    is to have 1) be a true function type and therefore 2) have a function call operator.



    So when a type has a user defined call operator and uses the sugary syntax, the call operator is not really being applied to the object, it is being applied to a true function type prvalue resulting from an expression like above.






    share|improve this answer










    New contributor




    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.




















    • Sounds logical to me, +1.

      – Paul Sanders
      1 hour ago











    • I'm not sure I understand this answer. If overload resolution does not consider objects with an overloaded function call operator, then a) how is it possible for overloading of the function call operator to function at all, and b) how come the error occur in cases where there is an object in the overload set!?

      – Michael Kenzel
      1 hour ago












    • booooot!!!!!!

      – Yakk - Adam Nevraumont
      51 mins ago













    5












    5








    5







    Lambdas are no different than regular functors or even plain function pointers in this regard. Overload resolution is only considering as candidates actual functions that are named sort. In other words, overload resolution is not going to consider literally anything that has a function call operator. Only true functions.



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

    namespace baz

    template<class T>
    void sort(T&&)


    namespace boot
    const auto sort = [](auto &&);


    namespace booot
    struct sort_functor

    template<class T>
    void operator()(T&&)const;
    ;

    constexpr sort_functor sort;


    namespace boooot

    void sort_func(int)

    constexpr auto sort = &sort_func;


    void foo ()
    using namespace std;
    using namespace baz;
    sort(1);


    void bar()
    using namespace std;
    using namespace boot;
    sort(1);



    void baar()
    using namespace std;
    using namespace booot;
    sort(1); // still an error



    void baaar()
    using namespace std;
    using namespace boooot;
    sort(1); // still the exact same error



    UPDATE: To answer Michael Kenzel's question below. Consider the function baar:



    void baar()
    using namespace std;
    using namespace booot;
    // sort(1); is syntatic sugar for:
    sort.operator()(1);



    Consider the expression sort.operator()(1). It actually consists of two operators. First the binary . operator is applied with operands sort and operator(). The result of this sub-expression is a true function type, and it is a prvalue. Although indeed it is a true function type, it is an rvalue and so it has no name. It is most definitely not named sort, so it cannot be considered for overload resolution of functions named sort.



    The sole purpose of the prvalue function type resulting from expressions like:



    some_instance.some_method
    some_instance_ptr->some_method
    (some_instance.*(&some_type::some_method))
    (some_instance_ptr->*(&some_type::some_method))


    is to have 1) be a true function type and therefore 2) have a function call operator.



    So when a type has a user defined call operator and uses the sugary syntax, the call operator is not really being applied to the object, it is being applied to a true function type prvalue resulting from an expression like above.






    share|improve this answer










    New contributor




    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.










    Lambdas are no different than regular functors or even plain function pointers in this regard. Overload resolution is only considering as candidates actual functions that are named sort. In other words, overload resolution is not going to consider literally anything that has a function call operator. Only true functions.



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

    namespace baz

    template<class T>
    void sort(T&&)


    namespace boot
    const auto sort = [](auto &&);


    namespace booot
    struct sort_functor

    template<class T>
    void operator()(T&&)const;
    ;

    constexpr sort_functor sort;


    namespace boooot

    void sort_func(int)

    constexpr auto sort = &sort_func;


    void foo ()
    using namespace std;
    using namespace baz;
    sort(1);


    void bar()
    using namespace std;
    using namespace boot;
    sort(1);



    void baar()
    using namespace std;
    using namespace booot;
    sort(1); // still an error



    void baaar()
    using namespace std;
    using namespace boooot;
    sort(1); // still the exact same error



    UPDATE: To answer Michael Kenzel's question below. Consider the function baar:



    void baar()
    using namespace std;
    using namespace booot;
    // sort(1); is syntatic sugar for:
    sort.operator()(1);



    Consider the expression sort.operator()(1). It actually consists of two operators. First the binary . operator is applied with operands sort and operator(). The result of this sub-expression is a true function type, and it is a prvalue. Although indeed it is a true function type, it is an rvalue and so it has no name. It is most definitely not named sort, so it cannot be considered for overload resolution of functions named sort.



    The sole purpose of the prvalue function type resulting from expressions like:



    some_instance.some_method
    some_instance_ptr->some_method
    (some_instance.*(&some_type::some_method))
    (some_instance_ptr->*(&some_type::some_method))


    is to have 1) be a true function type and therefore 2) have a function call operator.



    So when a type has a user defined call operator and uses the sugary syntax, the call operator is not really being applied to the object, it is being applied to a true function type prvalue resulting from an expression like above.







    share|improve this answer










    New contributor




    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    share|improve this answer



    share|improve this answer








    edited 28 mins ago





















    New contributor




    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.









    answered 1 hour ago









    MikeMike

    612




    612




    New contributor




    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.





    New contributor





    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.






    Mike is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
    Check out our Code of Conduct.












    • Sounds logical to me, +1.

      – Paul Sanders
      1 hour ago











    • I'm not sure I understand this answer. If overload resolution does not consider objects with an overloaded function call operator, then a) how is it possible for overloading of the function call operator to function at all, and b) how come the error occur in cases where there is an object in the overload set!?

      – Michael Kenzel
      1 hour ago












    • booooot!!!!!!

      – Yakk - Adam Nevraumont
      51 mins ago

















    • Sounds logical to me, +1.

      – Paul Sanders
      1 hour ago











    • I'm not sure I understand this answer. If overload resolution does not consider objects with an overloaded function call operator, then a) how is it possible for overloading of the function call operator to function at all, and b) how come the error occur in cases where there is an object in the overload set!?

      – Michael Kenzel
      1 hour ago












    • booooot!!!!!!

      – Yakk - Adam Nevraumont
      51 mins ago
















    Sounds logical to me, +1.

    – Paul Sanders
    1 hour ago





    Sounds logical to me, +1.

    – Paul Sanders
    1 hour ago













    I'm not sure I understand this answer. If overload resolution does not consider objects with an overloaded function call operator, then a) how is it possible for overloading of the function call operator to function at all, and b) how come the error occur in cases where there is an object in the overload set!?

    – Michael Kenzel
    1 hour ago






    I'm not sure I understand this answer. If overload resolution does not consider objects with an overloaded function call operator, then a) how is it possible for overloading of the function call operator to function at all, and b) how come the error occur in cases where there is an object in the overload set!?

    – Michael Kenzel
    1 hour ago














    booooot!!!!!!

    – Yakk - Adam Nevraumont
    51 mins ago





    booooot!!!!!!

    – Yakk - Adam Nevraumont
    51 mins ago













    1














    The problem here is not that the call to sort is ambiguous, but that the name sort is ambiguous. Name lookup happens before overload resolution.



    I believe the relevant section is [basic.lookup]/1, specifically




    […] The declarations found by name lookup shall either all denote the same entity or shall all denote functions or function templates; in the latter case, the declarations are said to form a set of overloaded functions ([over.load]). […]




    In your case, the name sort denotes both, the object boot::sort as well as the set of overloaded functions std::sort. Therefore, name lookup fails.



    Your code is not different from if you had written, for example



    namespace baz 
    int a;


    namespace boot
    int a;


    void foo()
    using namespace baz;
    using namespace boot;
    a = 42; // error: reference to 'a' is ambiguous



    Try it out here, note how the error message is the same as in your case, specifically referring to the name itself being ambiguous rather than the function call.






    share|improve this answer





























      1














      The problem here is not that the call to sort is ambiguous, but that the name sort is ambiguous. Name lookup happens before overload resolution.



      I believe the relevant section is [basic.lookup]/1, specifically




      […] The declarations found by name lookup shall either all denote the same entity or shall all denote functions or function templates; in the latter case, the declarations are said to form a set of overloaded functions ([over.load]). […]




      In your case, the name sort denotes both, the object boot::sort as well as the set of overloaded functions std::sort. Therefore, name lookup fails.



      Your code is not different from if you had written, for example



      namespace baz 
      int a;


      namespace boot
      int a;


      void foo()
      using namespace baz;
      using namespace boot;
      a = 42; // error: reference to 'a' is ambiguous



      Try it out here, note how the error message is the same as in your case, specifically referring to the name itself being ambiguous rather than the function call.






      share|improve this answer



























        1












        1








        1







        The problem here is not that the call to sort is ambiguous, but that the name sort is ambiguous. Name lookup happens before overload resolution.



        I believe the relevant section is [basic.lookup]/1, specifically




        […] The declarations found by name lookup shall either all denote the same entity or shall all denote functions or function templates; in the latter case, the declarations are said to form a set of overloaded functions ([over.load]). […]




        In your case, the name sort denotes both, the object boot::sort as well as the set of overloaded functions std::sort. Therefore, name lookup fails.



        Your code is not different from if you had written, for example



        namespace baz 
        int a;


        namespace boot
        int a;


        void foo()
        using namespace baz;
        using namespace boot;
        a = 42; // error: reference to 'a' is ambiguous



        Try it out here, note how the error message is the same as in your case, specifically referring to the name itself being ambiguous rather than the function call.






        share|improve this answer















        The problem here is not that the call to sort is ambiguous, but that the name sort is ambiguous. Name lookup happens before overload resolution.



        I believe the relevant section is [basic.lookup]/1, specifically




        […] The declarations found by name lookup shall either all denote the same entity or shall all denote functions or function templates; in the latter case, the declarations are said to form a set of overloaded functions ([over.load]). […]




        In your case, the name sort denotes both, the object boot::sort as well as the set of overloaded functions std::sort. Therefore, name lookup fails.



        Your code is not different from if you had written, for example



        namespace baz 
        int a;


        namespace boot
        int a;


        void foo()
        using namespace baz;
        using namespace boot;
        a = 42; // error: reference to 'a' is ambiguous



        Try it out here, note how the error message is the same as in your case, specifically referring to the name itself being ambiguous rather than the function call.







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited 1 min ago

























        answered 12 mins ago









        Michael KenzelMichael Kenzel

        5,03811020




        5,03811020



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55367269%2fgeneric-lambda-vs-generic-function-give-different-behaviour%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

            Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

            Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar