[ create a new paste ] login | about

Link: http://codepad.org/2lcnEjvI    [ raw code | output | fork ]

C++, pasted on Nov 11:
#include <iostream>
#include <boost/lambda/lambda.hpp>

template<class T>
struct  is_lambda_functor
{
	static const bool value = false;
};

// boost::lambda::_N だけの時
// T = boost::lambda::placeholder<...>
template<template <class> class T> 
struct  is_lambda_functor<boost::lambda::lambda_functor<T>>
{
	static const bool value = true;
};

// boost::lambda::_1 * boost::lambda::_2 の様に演算がある場合
// T = boost::lambda::lambda_functor_base
// F = boost::lambda::arithmetic_action
// A0 = boost::tuples::tuple
template<template <typename, typename> class T, class F, class A> 
struct  is_lambda_functor<typename boost::lambda::lambda_functor<T<F,A> > >
{
	static const bool value = true;
};

template<class F>
bool is_lambda(F)
{
	return is_lambda_functor<F>::value;
}

#include <functional>

void test()
{
	std::cout << is_lambda((boost::lambda::_1 )) << "\n";
	std::cout << is_lambda((boost::lambda::_1 * 2)) << "\n";
	std::cout << is_lambda((boost::lambda::_1 * boost::lambda::_2)) << "\n";
	std::cout << is_lambda((boost::lambda::_1 *  boost::lambda::_2 * 2* boost::lambda::_3)) << "\n";

	std::cout << is_lambda(boost::lambda::unlambda(boost::lambda::_1 * 2)) << "\n";
	std::cout << is_lambda(std::plus<int>()) << "\n";
}

int main()
{
	test();
}


Output:
1
2
Line 22: error: template argument 1 is invalid
compilation terminated due to -Wfatal-errors.


Create a new paste based on this one


Comments: