C++ Function bind repeating arguments to curried function

前端 未结 2 649
你的背包
你的背包 2021-01-18 04:13

I am trying to understand the concept of currying and calling a function which concats three strings but by passing only two strings and using the second argument twice.

2条回答
  •  感情败类
    2021-01-18 04:53

    Copying strings is expensive. Since std::bind thinks that the values of the placeholders are only used once, it performs a std::move on the strings. This is done for each Parameter and as a consequence, either b or c is a moved, that means empty string.

    You can change that behavior by explicitly saying what you mean, by passing the arguments by const-reference:

    string concatthreestrings(string const& a,string const& b,string const& c)
    

    Now, it should work.

提交回复
热议问题