C++ boost::lambda表达式不';不编译

C++ boost::lambda表达式不';不编译,c++,boost,boost-lambda,C++,Boost,Boost Lambda,我试图编写一个函数,使用boost lambda库计算两个码字之间的汉明距离。我有以下代码: #include <iostream> #include <numeric> #include <boost/function.hpp> #include <boost/lambda/lambda.hpp> #include <boost/lambda/if.hpp> #include <boost/bind.hpp> #inclu

我试图编写一个函数,使用boost lambda库计算两个码字之间的汉明距离。我有以下代码:

#include <iostream>
#include <numeric>
#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/if.hpp>
#include <boost/bind.hpp>
#include <boost/array.hpp>

template<typename Container>
int hammingDistance(Container & a, Container & b) {
  return std::inner_product(
    a.begin(),
    a.end(),
    b.begin(),
    (_1 + _2),
    boost::lambda::if_then_else_return(_1 != _2, 1, 0)
  );
}

int main() {
  boost::array<int, 3> a = {1, 0, 1}, b = {0, 1, 1};
  std::cout << hammingDistance(a, b) << std::endl;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括
模板
国际海明距离(集装箱和a、集装箱和b){
返回标准::内部产品(
a、 begin(),
a、 end(),
b、 begin(),
(_1 + _2),
boost::lambda::if_then_else_返回(_1!=_2,1,0)
);
}
int main(){
数组a={1,0,1},b={0,1,1};

std::cout我可能错了,但我认为在作为占位符(_1,_2等)的函数位于该名称空间之前,应该使用
名称空间boost::lambda;

第一个问题:在使用
boost/lambda
时,包括
而不是

第二个问题:在#includes之后,需要一个
使用名称空间boost::lambda

但仍然没有编译


编辑:

第三个问题-您需要6个参数作为
std::internal_product
,您缺少一个初始化参数。可能添加
0
作为第四个参数。

您应该调用
internal_product
作为
std::internal_product(a.begin(),a.end(),b.begin(),0,;
HammingDistance.cpp: In function ‘int hammingDistance(Container&, Container&)’:
HammingDistance.cpp:15: error: no match for ‘operator+’ in ‘<unnamed>::_1 + <unnamed>::_2’
HammingDistance.cpp:17: error: no match for ‘operator!=’ in ‘<unnamed>::_1 != <unnamed>::_2’
/usr/include/c++/4.3/boost/function/function_base.hpp:757: note: candidates are: bool boost::operator!=(boost::detail::function::useless_clear_type*, const boost::function_base&)
/usr/include/c++/4.3/boost/function/function_base.hpp:745: note:                 bool boost::operator!=(const boost::function_base&, boost::detail::function::useless_clear_type*)
#include <iostream>
#include <numeric>
#include <boost/function.hpp>
#include <boost/lambda/lambda.hpp>
#include <boost/lambda/if.hpp>
#include <boost/lambda/bind.hpp>
#include <boost/array.hpp>

using boost::lambda::_1;
using boost::lambda::_2;

template<typename Container>
int hammingDistance(Container & a, Container & b) {
  return std::inner_product(
    a.begin(),
    a.end(),
    b.begin(),
    0,
    (_1 + _2),
    boost::lambda::if_then_else_return(_1 != _2, 1, 0)
  );
}

int main() {
  boost::array<int, 3> a = {1, 0, 1}, b = {0, 1, 1};
  std::cout << hammingDistance(a, b) << std::endl;
}