mercredi 5 juillet 2017

How can I std::sqrt(boost::lambda::placeholder1_type)?

How do I std::sqrt() on a boost::lambda::placeholder1_type?

The following program compiles and executes fine. Somehow, it manages to convert boost::lambda::_1 to a double and multiply it with 5.0.

#include <boost/lambda/lambda.hpp>
#include <iostream>
#include <cmath>

int main() {

  std::array<double, 6> a = {1, 4, 9, 16, 25, 36};

  std::for_each(a.begin(), a.end(),
      std::cout << boost::lambda::_1 * 5.0 << " "
  );
}

However, if I replace the std::cout line with

std::cout << std::sqrt(boost::lambda::_1) << " "

the compiler (g++) says

no known conversion for argument 1 from ‘boost::lambda::placeholder1_type {aka const boost::lambda::lambda_functor >}’ to ‘double’

So, how can I take the square root from boost::lambda::_1 in this std::for_each loop?

Aucun commentaire:

Enregistrer un commentaire