Files
callable_traits/doc/make_function_example.qbk
badair f5459061f0 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
2016-05-03 03:52:18 -05:00

21 lines
1.4 KiB
Plaintext

[section Example: std::function sugar]
[heading Explanation]
At a glance, there appear to be around 260 [@http://stackoverflow.com/search?q=convert+std%3A%3Abind+to+std%3A%3Afunction search results] on Stack Overflow concerning the conversion from `std::bind` results to `std::function`, and around 340 [@http://stackoverflow.com/search?q=convert+lambda+to+std%3A%3Afunction search results] concerning the conversion of lambdas to `std::function`. There are few good reasons for converting `std::bind` result objects into `std::function` objects, and fewer still for creating `std::function` objects without explicitly specifying the function type. Regardless, here's a `make_function` function, which can...
# Construct an `std::function<T>` where T is not explicitly supplied by the user
# Construct an `std::function<T>` where T is the implied "signature" of an `std::placeholders` expression
`make_function` is rather silly, especially since we have no contextual reason for incurring the costs of type erasure. Still, it's a lightweight example of the kind of metaprogramming you can do with [libname].
[heading Usage]
[note Due to limitations in the Microsoft compiler, this example will not compile with MSVC. For more information, refer to the [link_compatibility_issues] section.]
[import ../example/make_function_example.cpp]
[make_function_example]
[heading Implementation]
[import ../example/make_function.hpp]
[make_function_header]
[endsect]