mirror of
https://github.com/boostorg/callable_traits.git
synced 2026-02-13 12:22:18 +00:00
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
21 lines
1.4 KiB
Plaintext
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]
|