Last active
December 27, 2015 11:39
-
-
Save erikerlandson/7319975 to your computer and use it in GitHub Desktop.
Demonstrate referring to an argument type in the BOOST_PARAMETER_FUNCTION macro
This file contains 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
#include <boost/parameter/name.hpp> | |
#include <boost/parameter/preprocessor.hpp> | |
BOOST_PARAMETER_NAME(b) | |
BOOST_PARAMETER_NAME(c) | |
BOOST_PARAMETER_FUNCTION( | |
// Deduce return type from an argument type | |
// This is not documented, but seems like it could be officially supported: | |
(typename boost::parameter::value_type<Args, tag::c, int>::type), | |
ffff, | |
tag, | |
(required | |
(b, *)) | |
(optional | |
(c, *, 11)) | |
) | |
{ | |
return b + c; | |
} | |
int main(int argc, char** argv) { | |
std::cout << ffff(3, _c = 4) << "\n"; // return value is integer | |
std::cout << ffff(3, _c = 4.5) << "\n"; // return value is floating point | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment