Skip to content

Instantly share code, notes, and snippets.

@erikerlandson
Last active December 27, 2015 11:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save erikerlandson/7319975 to your computer and use it in GitHub Desktop.
Save erikerlandson/7319975 to your computer and use it in GitHub Desktop.
Demonstrate referring to an argument type in the BOOST_PARAMETER_FUNCTION macro
#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