mirror of
https://github.com/boostorg/callable_traits.git
synced 2026-02-10 11:22:13 +00:00
adding interface example
fixing build errors adding Boost to travis.yml fixing travis.yml fixing travis.yml fixing travis.yml, fixing for libstdc++ bug fixing travis.yml fixing travis.yml adding is_like_function fixing interface example, doc gen removing rogue tab characters fixing build error adding FunctionTypes section in documentation removing empty note fixing misspelling of inheritance
This commit is contained in:
54
example/make_function_example.cpp
Normal file
54
example/make_function_example.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/*<-
|
||||
Copyright Barrett Adair 2016
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE.md or copy at http ://boost.org/LICENSE_1_0.txt)
|
||||
->*/
|
||||
|
||||
#include <callable_traits/config.hpp>
|
||||
|
||||
#ifdef CALLABLE_TRAITS_DISABLE_CONSTEXPR_CHECKS
|
||||
int main(){ return 0; }
|
||||
#else
|
||||
|
||||
//[ make_function_example
|
||||
#include <cassert>
|
||||
|
||||
#include "make_function.hpp"
|
||||
|
||||
using namespace example;
|
||||
using namespace std::placeholders;
|
||||
|
||||
int add(int i, int j) {
|
||||
return i + j;
|
||||
}
|
||||
|
||||
struct adder {
|
||||
|
||||
int eval(int i, int j) const {
|
||||
return i + j;
|
||||
}
|
||||
};
|
||||
|
||||
int main() {
|
||||
|
||||
// function pointer
|
||||
auto f = make_function(&add);
|
||||
assert(f(99, 1) == 100);
|
||||
|
||||
// function reference
|
||||
f = make_function(add);
|
||||
assert(f(99, 1) == 100);
|
||||
|
||||
// member function pointer (bound to object)
|
||||
f = make_function(&adder::eval, adder{}, _1, _2);
|
||||
assert(f(99, 1) == 100);
|
||||
|
||||
// lambda
|
||||
f = make_function([](int i, int j) {
|
||||
return i + j;
|
||||
});
|
||||
|
||||
assert(f(99, 1) == 100);
|
||||
}
|
||||
//]
|
||||
#endif
|
||||
Reference in New Issue
Block a user