Created
October 5, 2016 07:25
-
-
Save tlkahn/4293bb37d3b176f692ac8a508832c84c to your computer and use it in GitHub Desktop.
create a closure in C++
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct db_sum: public std::unary_function<boost::any, void> { | |
private: | |
double& sum_; | |
public: | |
explicit db_sum(double& sum) | |
: sum_(sum) | |
{} | |
void operator()(const cell_t& value) { | |
const std::type_info& ti = value.type(); | |
if (ti == typeid(int)) { | |
sum_ += boost::any_cast<int>(value); | |
} else if (ti == typeid(float)) { | |
sum_ += boost::any_cast<float>(value); | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment