diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 18:45:59 +0000 |
commit | 19fcec84d8d7d21e796c7624e521b60d28ee21ed (patch) | |
tree | 42d26aa27d1e3f7c0b8bd3fd14e7d7082f5008dc /src/boost/libs/parameter/test/literate | |
parent | Initial commit. (diff) | |
download | ceph-upstream/16.2.11+ds.tar.xz ceph-upstream/16.2.11+ds.zip |
Adding upstream version 16.2.11+ds.upstream/16.2.11+dsupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/boost/libs/parameter/test/literate')
32 files changed, 1491 insertions, 0 deletions
diff --git a/src/boost/libs/parameter/test/literate/README b/src/boost/libs/parameter/test/literate/README new file mode 100644 index 000000000..da7f5d54c --- /dev/null +++ b/src/boost/libs/parameter/test/literate/README @@ -0,0 +1,6 @@ +These tests were extracted from the Boost.Parameter documentation +with: + +python ../../../../tools/litre/tool.py \ + ../../../../libs/parameter/doc/index.rst \ + --dump_dir=. diff --git a/src/boost/libs/parameter/test/literate/building-argumentpacks0.cpp b/src/boost/libs/parameter/test/literate/building-argumentpacks0.cpp new file mode 100644 index 000000000..d80f2f9f0 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/building-argumentpacks0.cpp @@ -0,0 +1,61 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +BOOST_PARAMETER_NAME(index) + +template <typename ArgumentPack> +int print_index(ArgumentPack const& args) +{ + std::cout << "index = " << args[_index] << std::endl; + return 0; +} + +BOOST_PARAMETER_NAME(name) + +template <typename ArgumentPack> +int print_name_and_index(ArgumentPack const& args) +{ + std::cout << "name = " << args[_name] << "; "; + return print_index(args); +} + +#include <boost/core/lightweight_test.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/if.hpp> +#include <boost/type_traits/is_convertible.hpp> + +int main() +{ + int x = print_index(_index = 3); // prints "index = 3" + int y = print_name_and_index((_index = 3, _name = "jones")); + boost::parameter::parameters< + boost::parameter::required< + tag::name + , boost::mpl::if_< + boost::is_convertible<boost::mpl::_,char const*> + , boost::mpl::true_ + , boost::mpl::false_ + > + > + , boost::parameter::optional< + tag::index + , boost::mpl::if_< + boost::is_convertible<boost::mpl::_,int> + , boost::mpl::true_ + , boost::mpl::false_ + > + > + > spec; + char const sam[] = "sam"; + int twelve = 12; + int z0 = print_name_and_index(spec(sam, twelve)); + int z1 = print_name_and_index(spec(_index=12, _name="sam")); + BOOST_TEST(!x); + BOOST_TEST(!y); + BOOST_TEST(!z0); + BOOST_TEST(!z1); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/class-template-skeleton0.cpp b/src/boost/libs/parameter/test/literate/class-template-skeleton0.cpp new file mode 100644 index 000000000..bc8095e97 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/class-template-skeleton0.cpp @@ -0,0 +1,16 @@ + +#include <boost/parameter.hpp> + +namespace boost { namespace python { + + template < + typename A0 + , typename A1 = boost::parameter::void_ + , typename A2 = boost::parameter::void_ + , typename A3 = boost::parameter::void_ + > + struct class_ + { + }; +}} + diff --git a/src/boost/libs/parameter/test/literate/deduced-parameters0.cpp b/src/boost/libs/parameter/test/literate/deduced-parameters0.cpp new file mode 100644 index 000000000..f2e1d4caf --- /dev/null +++ b/src/boost/libs/parameter/test/literate/deduced-parameters0.cpp @@ -0,0 +1,101 @@ + +#include <boost/parameter.hpp> + +BOOST_PARAMETER_NAME(name) +BOOST_PARAMETER_NAME(func) +BOOST_PARAMETER_NAME(docstring) +BOOST_PARAMETER_NAME(keywords) +BOOST_PARAMETER_NAME(policies) + +struct default_call_policies +{ +}; + +struct no_keywords +{ +}; + +struct keywords +{ +}; + +#include <boost/mpl/bool.hpp> + +template <typename T> +struct is_keyword_expression + : boost::mpl::false_ +{ +}; + +template <> +struct is_keyword_expression<keywords> + : boost::mpl::true_ +{ +}; + +default_call_policies some_policies; + +void f() +{ +} + +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/type_traits/is_convertible.hpp> + +char const*& blank_char_ptr() +{ + static char const* larr = ""; + return larr; +} + +BOOST_PARAMETER_FUNCTION( + (bool), def, tag, + (required (name,(char const*)) (func,*) ) // nondeduced + (deduced + (optional + (docstring, (char const*), blank_char_ptr()) + (keywords + // see 5 + , *(is_keyword_expression<boost::mpl::_>) + , no_keywords() + ) + (policies + , *( + boost::mpl::eval_if< + boost::is_convertible<boost::mpl::_,char const*> + , boost::mpl::false_ + , boost::mpl::if_< + // see 5 + is_keyword_expression<boost::mpl::_> + , boost::mpl::false_ + , boost::mpl::true_ + > + > + ) + , default_call_policies() + ) + ) + ) +) +{ + return true; +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + char const* f_name = "f"; + def(f_name, &f, some_policies, "Documentation for f"); + def(f_name, &f, "Documentation for f", some_policies); + def( + f_name + , &f + , _policies = some_policies + , "Documentation for f" + ); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/deduced-template-parameters0.cpp b/src/boost/libs/parameter/test/literate/deduced-template-parameters0.cpp new file mode 100644 index 000000000..2fb1cd82b --- /dev/null +++ b/src/boost/libs/parameter/test/literate/deduced-template-parameters0.cpp @@ -0,0 +1,214 @@ + +#include <boost/parameter.hpp> + +namespace boost { namespace python { + + BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type) + BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list) + BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type) + BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable) +}} + +namespace boost { namespace python { + namespace detail { + + struct bases_base + { + }; + } + + template <typename A0 = void, typename A1 = void, typename A2 = void> + struct bases : detail::bases_base + { + }; +}} + +#include <boost/mpl/bool.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/eval_if.hpp> +#include <boost/noncopyable.hpp> +#include <boost/type_traits/is_same.hpp> +#include <boost/type_traits/is_base_of.hpp> +#include <boost/type_traits/is_class.hpp> +#include <boost/config.hpp> + +#if !defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) || \ + !(1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) +#include <boost/type_traits/is_scalar.hpp> +#endif + +namespace boost { namespace python { + + typedef boost::parameter::parameters< + boost::parameter::required< + tag::class_type +#if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) && \ + (1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) + , boost::mpl::if_< + boost::is_class<boost::mpl::_> + , boost::mpl::true_ + , boost::mpl::false_ + > +#else + , boost::mpl::if_< + boost::is_scalar<boost::mpl::_> + , boost::mpl::false_ + , boost::mpl::true_ + > +#endif + > + , boost::parameter::optional< + boost::parameter::deduced<tag::base_list> + , boost::mpl::if_< + boost::is_base_of<detail::bases_base,boost::mpl::_> + , boost::mpl::true_ + , boost::mpl::false_ + > + > + , boost::parameter::optional< + boost::parameter::deduced<tag::held_type> + , boost::mpl::eval_if< + boost::is_base_of<detail::bases_base,boost::mpl::_> + , boost::mpl::false_ + , boost::mpl::if_< + boost::is_same<boost::noncopyable,boost::mpl::_> + , boost::mpl::false_ + , boost::mpl::true_ + > + > + > + , boost::parameter::optional< + boost::parameter::deduced<tag::copyable> + , boost::mpl::if_< + boost::is_same<boost::noncopyable,boost::mpl::_> + , boost::mpl::true_ + , boost::mpl::false_ + > + > + > class_signature; + + template < + typename A0 + , typename A1 = boost::parameter::void_ + , typename A2 = boost::parameter::void_ + , typename A3 = boost::parameter::void_ + > + struct class_ + { + // Create ArgumentPack + typedef typename boost::python::class_signature::BOOST_NESTED_TEMPLATE + bind<A0,A1,A2,A3>::type args; + + // Extract first logical parameter. + typedef typename boost::parameter::value_type< + args,boost::python::tag::class_type + >::type class_type; + + typedef typename boost::parameter::value_type< + args,boost::python::tag::base_list,boost::python::bases<> + >::type base_list; + + typedef typename boost::parameter::value_type< + args,boost::python::tag::held_type,class_type + >::type held_type; + + typedef typename boost::parameter::value_type< + args,boost::python::tag::copyable,void + >::type copyable; + }; +}} + +struct B +{ +}; + +struct D +{ +}; + +typedef boost::python::class_<B,boost::noncopyable> c1; + +#include <memory> + +#if defined(BOOST_NO_CXX11_SMART_PTR) +typedef boost::python::class_<D,std::auto_ptr<D>,boost::python::bases<B> > c2; +#else +typedef boost::python::class_< + D,std::unique_ptr<D>,boost::python::bases<B> +> c2; +#endif + +#include <boost/mpl/assert.hpp> +#include <boost/mpl/aux_/test.hpp> + +MPL_TEST_CASE() +{ + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::class_type,B> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::base_list,boost::python::bases<> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::held_type,B> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::copyable,boost::noncopyable> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::class_type,D> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::base_list,boost::python::bases<B> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +#if defined(BOOST_NO_CXX11_SMART_PTR) + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::held_type,std::auto_ptr<D> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +#else + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::held_type,std::unique_ptr<D> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +#endif // BOOST_NO_CXX11_SMART_PTR + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::copyable,void> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +} + diff --git a/src/boost/libs/parameter/test/literate/default-expression-evaluation0.cpp b/src/boost/libs/parameter/test/literate/default-expression-evaluation0.cpp new file mode 100644 index 000000000..87c99d32e --- /dev/null +++ b/src/boost/libs/parameter/test/literate/default-expression-evaluation0.cpp @@ -0,0 +1,48 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +BOOST_PARAMETER_NAME(graph) +BOOST_PARAMETER_NAME(visitor) +BOOST_PARAMETER_NAME(root_vertex) +BOOST_PARAMETER_NAME(index_map) +BOOST_PARAMETER_NAME(color_map) + +#include <boost/graph/depth_first_search.hpp> // for dfs_visitor + +BOOST_PARAMETER_FUNCTION((bool), depth_first_search, tag, + (required + (graph, *) + (visitor, *) + (root_vertex, *) + (index_map, *) + (color_map, *) + ) +) +{ + std::cout << "graph=" << graph; + std::cout << std::endl; + std::cout << "visitor=" << visitor; + std::cout << std::endl; + std::cout << "root_vertex=" << root_vertex; + std::cout << std::endl; + std::cout << "index_map=" << index_map; + std::cout << std::endl; + std::cout << "color_map=" << color_map; + std::cout << std::endl; + return true; +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + char const* g = "1"; + depth_first_search(1, 2, 3, 4, 5); + depth_first_search( + g, '2', _color_map = '5' + , _index_map = "4", _root_vertex = "3" + ); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/defining-the-keywords0.cpp b/src/boost/libs/parameter/test/literate/defining-the-keywords0.cpp new file mode 100644 index 000000000..e6525750e --- /dev/null +++ b/src/boost/libs/parameter/test/literate/defining-the-keywords0.cpp @@ -0,0 +1,11 @@ + +#include <boost/parameter/name.hpp> + +namespace graphs { + + BOOST_PARAMETER_NAME(graph) // Note: no semicolon + BOOST_PARAMETER_NAME(visitor) + BOOST_PARAMETER_NAME(root_vertex) + BOOST_PARAMETER_NAME(index_map) + BOOST_PARAMETER_NAME(color_map) +} diff --git a/src/boost/libs/parameter/test/literate/defining-the-keywords1.cpp b/src/boost/libs/parameter/test/literate/defining-the-keywords1.cpp new file mode 100644 index 000000000..8107dce19 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/defining-the-keywords1.cpp @@ -0,0 +1,21 @@ + +#include <boost/parameter/keyword.hpp> + +namespace graphs { + namespace tag { + + // keyword tag type + struct graph + { + typedef boost::parameter::forward_reference qualifier; + }; + } + + namespace // unnamed + { + // A reference to the keyword object + boost::parameter::keyword<tag::graph> const& _graph + = boost::parameter::keyword<tag::graph>::instance; + } +} + diff --git a/src/boost/libs/parameter/test/literate/exercising-the-code-so-far0.cpp b/src/boost/libs/parameter/test/literate/exercising-the-code-so-far0.cpp new file mode 100644 index 000000000..3098f09be --- /dev/null +++ b/src/boost/libs/parameter/test/literate/exercising-the-code-so-far0.cpp @@ -0,0 +1,193 @@ + +#include <boost/parameter.hpp> + +namespace boost { namespace python { + + BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type) + BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list) + BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type) + BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable) + + template <typename B = int> + struct bases + { + }; +}} + +#include <boost/mpl/bool.hpp> +#include <boost/mpl/placeholders.hpp> +#include <boost/mpl/if.hpp> +#include <boost/mpl/is_sequence.hpp> +#include <boost/type_traits/is_class.hpp> +#include <boost/config.hpp> + +#if !defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) || \ + !(1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) +#include <boost/type_traits/is_scalar.hpp> +#endif + +namespace boost { namespace python { + + typedef boost::parameter::parameters< + boost::parameter::required< + tag::class_type +#if defined(BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) && \ + (1 == BOOST_TT_HAS_CONFORMING_IS_CLASS_IMPLEMENTATION) + , boost::mpl::if_< + boost::is_class<boost::mpl::_> + , boost::mpl::true_ + , boost::mpl::false_ + > +#else + , boost::mpl::if_< + boost::is_scalar<boost::mpl::_> + , boost::mpl::false_ + , boost::mpl::true_ + > +#endif + > + , boost::parameter::optional< + tag::base_list + , boost::mpl::is_sequence<boost::mpl::_> + > + , boost::parameter::optional<tag::held_type> + , boost::parameter::optional<tag::copyable> + > class_signature; +}} // namespace boost::python + +namespace boost { namespace python { + + template < + typename A0 + , typename A1 = boost::parameter::void_ + , typename A2 = boost::parameter::void_ + , typename A3 = boost::parameter::void_ + > + struct class_ + { + // Create ArgumentPack + typedef typename class_signature::BOOST_NESTED_TEMPLATE bind< + A0, A1, A2, A3 + >::type args; + + // Extract first logical parameter. + typedef typename boost::parameter::value_type< + args, tag::class_type + >::type class_type; + + typedef typename boost::parameter::value_type< + args, tag::base_list, boost::python::bases<> + >::type base_list; + + typedef typename boost::parameter::value_type< + args, tag::held_type, class_type + >::type held_type; + + typedef typename boost::parameter::value_type< + args, tag::copyable, void + >::type copyable; + }; +}} // namespace boost::python + +struct B +{ +}; + +struct D +{ +}; + +#include <boost/noncopyable.hpp> +#include <memory> + +typedef boost::python::class_< + boost::python::class_type<B> + , boost::python::copyable<boost::noncopyable> +> c1; + +typedef boost::python::class_< + D + , boost::python::held_type< +#if defined(BOOST_NO_CXX11_SMART_PTR) + std::auto_ptr<D> +#else + std::unique_ptr<D> +#endif + > + , boost::python::base_list<boost::python::bases<B> > +> c2; + +#include <boost/type_traits/is_same.hpp> +#include <boost/mpl/aux_/test.hpp> +#include <boost/mpl/assert.hpp> + +MPL_TEST_CASE() +{ + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::class_type,B> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::base_list,boost::python::bases<> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::held_type,B> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c1::copyable,boost::noncopyable> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::class_type,D> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::base_list,boost::python::bases<B> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +#if defined(BOOST_NO_CXX11_SMART_PTR) + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::held_type,std::auto_ptr<D> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +#else + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::held_type,std::unique_ptr<D> > + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +#endif // BOOST_NO_CXX11_SMART_PTR + BOOST_MPL_ASSERT(( + boost::mpl::if_< + boost::is_same<c2::copyable,void> + , boost::mpl::true_ + , boost::mpl::false_ + >::type + )); +} + diff --git a/src/boost/libs/parameter/test/literate/extracting-parameter-types0.cpp b/src/boost/libs/parameter/test/literate/extracting-parameter-types0.cpp new file mode 100644 index 000000000..22e458242 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/extracting-parameter-types0.cpp @@ -0,0 +1,55 @@ + +#include <boost/parameter.hpp> + +BOOST_PARAMETER_NAME(name) +BOOST_PARAMETER_NAME(index) + +template <typename T> +#if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) +void noop(T&&) +#else +void noop(T&) +#endif +{ +} + +#if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) +#include <utility> +#endif + +template <typename Name, typename Index> +#if defined(BOOST_PARAMETER_HAS_PERFECT_FORWARDING) +int deduce_arg_types_impl(Name&& name, Index&& index) +{ + noop(std::forward<Name>(name)); + noop(std::forward<Index>(index)); + return index; +} +#else +int deduce_arg_types_impl(Name& name, Index& index) +{ + Name& n2 = name; // we know the types + Index& i2 = index; + noop(n2); + noop(i2); + return index; +} +#endif + +template <typename ArgumentPack> +int deduce_arg_types(ArgumentPack const& args) +{ + return deduce_arg_types_impl(args[_name], args[_index|42]); +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + int a1 = deduce_arg_types((_name = "foo")); + int a2 = deduce_arg_types((_name = "foo", _index = 3)); + BOOST_TEST_EQ(a1, 42); + BOOST_TEST_EQ(a2, 3); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/extracting-parameter-types1.cpp b/src/boost/libs/parameter/test/literate/extracting-parameter-types1.cpp new file mode 100644 index 000000000..64694f51a --- /dev/null +++ b/src/boost/libs/parameter/test/literate/extracting-parameter-types1.cpp @@ -0,0 +1,21 @@ + +#include <boost/parameter.hpp> + +BOOST_PARAMETER_NAME(index) + +template <typename ArgumentPack> +typename boost::parameter::value_type<ArgumentPack,tag::index,int>::type + twice_index(ArgumentPack const& args) +{ + return 2 * args[_index|42]; +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + int six = twice_index(_index = 3); + BOOST_TEST_EQ(six, 6); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/fine-grained-name-control0.cpp b/src/boost/libs/parameter/test/literate/fine-grained-name-control0.cpp new file mode 100644 index 000000000..688658adc --- /dev/null +++ b/src/boost/libs/parameter/test/literate/fine-grained-name-control0.cpp @@ -0,0 +1,21 @@ + +#include <boost/parameter.hpp> + +BOOST_PARAMETER_NAME((pass_foo, keywords) foo) + +BOOST_PARAMETER_FUNCTION( + (int), f, keywords, (required (foo, *)) +) +{ + return foo + 1; +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + int x = f(pass_foo = 41); + BOOST_TEST_EQ(x, 42); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/handling-out-parameters0.cpp b/src/boost/libs/parameter/test/literate/handling-out-parameters0.cpp new file mode 100644 index 000000000..fb6bc9396 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/handling-out-parameters0.cpp @@ -0,0 +1,33 @@ + +#include <boost/parameter.hpp> + +namespace boost { + + int vertex_index = 0; + + template <typename T = int> + struct dfs_visitor + { + }; +} + +BOOST_PARAMETER_NAME(graph) +BOOST_PARAMETER_NAME(visitor) +BOOST_PARAMETER_NAME(root_vertex) +BOOST_PARAMETER_NAME(index_map) +BOOST_PARAMETER_NAME(in_out(color_map)) + +BOOST_PARAMETER_FUNCTION((void), f, tag, + (required (graph, *)) + (optional + (visitor, *, boost::dfs_visitor<>()) + (root_vertex, *, *vertices(graph).first) + (index_map, *, get(boost::vertex_index,graph)) + (color_map, *, + default_color_map(num_vertices(graph), index_map) + ) + ) +) +{ +} + diff --git a/src/boost/libs/parameter/test/literate/headers-and-namespaces0.cpp b/src/boost/libs/parameter/test/literate/headers-and-namespaces0.cpp new file mode 100644 index 000000000..a3b138d2e --- /dev/null +++ b/src/boost/libs/parameter/test/literate/headers-and-namespaces0.cpp @@ -0,0 +1,3 @@ +#include <boost/parameter/keyword.hpp> +using boost::parameter::keyword; + diff --git a/src/boost/libs/parameter/test/literate/lazy-default-computation0.cpp b/src/boost/libs/parameter/test/literate/lazy-default-computation0.cpp new file mode 100644 index 000000000..ad8a3e83e --- /dev/null +++ b/src/boost/libs/parameter/test/literate/lazy-default-computation0.cpp @@ -0,0 +1,28 @@ + +#include <boost/parameter.hpp> +#include <string> + +BOOST_PARAMETER_NAME(s1) +BOOST_PARAMETER_NAME(s2) +BOOST_PARAMETER_NAME(s3) + +template <typename ArgumentPack> +std::string f(ArgumentPack const& args) +{ + std::string const& s1 = args[_s1]; + std::string const& s2 = args[_s2]; + typename boost::parameter::binding< + ArgumentPack,tag::s3,std::string + >::type s3 = args[_s3|(s1+s2)]; // always constructs s1+s2 + return s3; +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + std::string x = f((_s1="hello,", _s2=" world", _s3="hi world")); + BOOST_TEST_EQ(x, std::string("hi world")); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/lazy-default-computation1.cpp b/src/boost/libs/parameter/test/literate/lazy-default-computation1.cpp new file mode 100644 index 000000000..c6ecc1981 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/lazy-default-computation1.cpp @@ -0,0 +1,37 @@ + +#include <boost/bind.hpp> +#include <boost/ref.hpp> +#include <boost/parameter.hpp> +#include <string> +#include <functional> + +BOOST_PARAMETER_NAME(s1) +BOOST_PARAMETER_NAME(s2) +BOOST_PARAMETER_NAME(s3) + +template <typename ArgumentPack> +std::string f(ArgumentPack const& args) +{ + std::string const& s1 = args[_s1]; + std::string const& s2 = args[_s2]; + typename boost::parameter::binding< + ArgumentPack, tag::s3, std::string + >::type s3 = args[ + _s3 || boost::bind( + std::plus<std::string>() + , boost::ref(s1) + , boost::ref(s2) + ) + ]; + return s3; +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + std::string x = f((_s1="hello,", _s2=" world", _s3="hi world")); + BOOST_TEST_EQ(x, std::string("hi world")); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/namespaces0.cpp b/src/boost/libs/parameter/test/literate/namespaces0.cpp new file mode 100644 index 000000000..a0bd827ca --- /dev/null +++ b/src/boost/libs/parameter/test/literate/namespaces0.cpp @@ -0,0 +1,27 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +namespace lib { + + BOOST_PARAMETER_NAME(name) + BOOST_PARAMETER_NAME(index) + + BOOST_PARAMETER_FUNCTION( + (int), f, tag, (optional (name,*,"bob")(index,(int),1)) + ) + { + std::cout << name << ":" << index << std::endl; + return index; + } +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + int x = lib::f(lib::_name = "jill", lib::_index = 1); + BOOST_TEST_EQ(x, 1); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/namespaces1.cpp b/src/boost/libs/parameter/test/literate/namespaces1.cpp new file mode 100644 index 000000000..4d5ff786c --- /dev/null +++ b/src/boost/libs/parameter/test/literate/namespaces1.cpp @@ -0,0 +1,30 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +namespace lib { + + BOOST_PARAMETER_NAME(name) + BOOST_PARAMETER_NAME(index) + + BOOST_PARAMETER_FUNCTION( + (int), f, tag, (optional (name,*,"bob")(index,(int),1)) + ) + { + std::cout << name << ":" << index << std::endl; + return index; + } +} + +#include <boost/core/lightweight_test.hpp> + +using lib::_name; +using lib::_index; + +int main() +{ + int x = lib::f(_name = "jill", _index = 1); + BOOST_TEST_EQ(x, 1); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/namespaces2.cpp b/src/boost/libs/parameter/test/literate/namespaces2.cpp new file mode 100644 index 000000000..c4a5d4f55 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/namespaces2.cpp @@ -0,0 +1,29 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +namespace lib { + + BOOST_PARAMETER_NAME(name) + BOOST_PARAMETER_NAME(index) + + BOOST_PARAMETER_FUNCTION( + (int), f, tag, (optional (name,*,"bob")(index,(int),1)) + ) + { + std::cout << name << ":" << index << std::endl; + return index; + } +} + +#include <boost/core/lightweight_test.hpp> + +using namespace lib; + +int main() +{ + int x = f(_name = "jill", _index = 3); + BOOST_TEST_EQ(x, 3); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/namespaces3.cpp b/src/boost/libs/parameter/test/literate/namespaces3.cpp new file mode 100644 index 000000000..6f5260f72 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/namespaces3.cpp @@ -0,0 +1,31 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +namespace lib { + namespace keywords { + + BOOST_PARAMETER_NAME(name) + BOOST_PARAMETER_NAME(index) + } + + BOOST_PARAMETER_FUNCTION( + (int), f, keywords::tag, (optional (name,*,"bob")(index,(int),1)) + ) + { + std::cout << name << ":" << index << std::endl; + return index; + } +} + +#include <boost/core/lightweight_test.hpp> + +using namespace lib::keywords; + +int main() +{ + int x = lib::f(_name = "bob", _index = 2); + BOOST_TEST_EQ(x, 2); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/optional-parameters0.cpp b/src/boost/libs/parameter/test/literate/optional-parameters0.cpp new file mode 100644 index 000000000..fb6bc9396 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/optional-parameters0.cpp @@ -0,0 +1,33 @@ + +#include <boost/parameter.hpp> + +namespace boost { + + int vertex_index = 0; + + template <typename T = int> + struct dfs_visitor + { + }; +} + +BOOST_PARAMETER_NAME(graph) +BOOST_PARAMETER_NAME(visitor) +BOOST_PARAMETER_NAME(root_vertex) +BOOST_PARAMETER_NAME(index_map) +BOOST_PARAMETER_NAME(in_out(color_map)) + +BOOST_PARAMETER_FUNCTION((void), f, tag, + (required (graph, *)) + (optional + (visitor, *, boost::dfs_visitor<>()) + (root_vertex, *, *vertices(graph).first) + (index_map, *, get(boost::vertex_index,graph)) + (color_map, *, + default_color_map(num_vertices(graph), index_map) + ) + ) +) +{ +} + diff --git a/src/boost/libs/parameter/test/literate/parameter-enabled-constructors0.cpp b/src/boost/libs/parameter/test/literate/parameter-enabled-constructors0.cpp new file mode 100644 index 000000000..96663a053 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/parameter-enabled-constructors0.cpp @@ -0,0 +1,36 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +BOOST_PARAMETER_NAME(name) +BOOST_PARAMETER_NAME(index) + +struct myclass_impl +{ + template <typename ArgumentPack> + myclass_impl(ArgumentPack const& args) + { + std::cout << "name = " << args[_name]; + std::cout << "; index = " << args[_index | 42]; + std::cout << std::endl; + } +}; + +struct myclass : myclass_impl +{ + BOOST_PARAMETER_CONSTRUCTOR( + myclass, (myclass_impl), tag + , (required (name,*)) (optional (index,*)) + ) // no semicolon +}; + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + myclass x("bob", 3); // positional + myclass y(_index = 12, _name = "sally"); // named + myclass z("june"); // positional/defaulted + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/parameter-enabled-function-call-operators0.cpp b/src/boost/libs/parameter/test/literate/parameter-enabled-function-call-operators0.cpp new file mode 100644 index 000000000..f623ef85d --- /dev/null +++ b/src/boost/libs/parameter/test/literate/parameter-enabled-function-call-operators0.cpp @@ -0,0 +1,29 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +using namespace boost::parameter; + +BOOST_PARAMETER_NAME(arg1) +BOOST_PARAMETER_NAME(arg2) + +struct callable2 +{ + BOOST_PARAMETER_CONST_FUNCTION_CALL_OPERATOR( + (void), tag, (required (arg1,(int))(arg2,(int))) + ) + { + std::cout << arg1 << ", " << arg2 << std::endl; + } +}; + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + callable2 c2; + callable2 const& c2_const = c2; + c2_const(1, 2); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/parameter-enabled-member-functions0.cpp b/src/boost/libs/parameter/test/literate/parameter-enabled-member-functions0.cpp new file mode 100644 index 000000000..04eecbf1b --- /dev/null +++ b/src/boost/libs/parameter/test/literate/parameter-enabled-member-functions0.cpp @@ -0,0 +1,29 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +using namespace boost::parameter; + +BOOST_PARAMETER_NAME(arg1) +BOOST_PARAMETER_NAME(arg2) + +struct callable2 +{ + BOOST_PARAMETER_CONST_MEMBER_FUNCTION( + (void), call, tag, (required (arg1,(int))(arg2,(int))) + ) + { + std::cout << arg1 << ", " << arg2 << std::endl; + } +}; + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + callable2 c2; + callable2 const& c2_const = c2; + c2_const.call(1, 2); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/parameter-enabled-member-functions1.cpp b/src/boost/libs/parameter/test/literate/parameter-enabled-member-functions1.cpp new file mode 100644 index 000000000..3aaae2357 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/parameter-enabled-member-functions1.cpp @@ -0,0 +1,21 @@ + +#include <boost/parameter.hpp> + +BOOST_PARAMETER_NAME(arg1) +BOOST_PARAMETER_NAME(arg2) + +using namespace boost::parameter; + +struct callable2 +{ + BOOST_PARAMETER_CONST_MEMBER_FUNCTION( + (void), call, tag, (required (arg1,(int))(arg2,(int))) + ) + { + call_impl(arg1, arg2); + } + + private: + void call_impl(int, int); // implemented elsewhere. +}; + diff --git a/src/boost/libs/parameter/test/literate/predicate-requirements0.cpp b/src/boost/libs/parameter/test/literate/predicate-requirements0.cpp new file mode 100644 index 000000000..d39ae964a --- /dev/null +++ b/src/boost/libs/parameter/test/literate/predicate-requirements0.cpp @@ -0,0 +1,189 @@ + +#include <boost/parameter.hpp> + +BOOST_PARAMETER_NAME((_graph, graphs) graph) +BOOST_PARAMETER_NAME((_visitor, graphs) visitor) +BOOST_PARAMETER_NAME((_root_vertex, graphs) in(root_vertex)) +BOOST_PARAMETER_NAME((_index_map, graphs) in(index_map)) +BOOST_PARAMETER_NAME((_color_map, graphs) in_out(color_map)) + +#include <boost/graph/graph_traits.hpp> +#include <boost/mpl/bool.hpp> +#include <boost/mpl/if.hpp> +#include <boost/type_traits/is_convertible.hpp> +#include <boost/type_traits/is_integral.hpp> +#include <boost/type_traits/is_same.hpp> + +struct vertex_descriptor_predicate +{ + template <typename T, typename Args> + struct apply + : boost::mpl::if_< + boost::is_convertible< + T + , typename boost::graph_traits< + typename boost::parameter::value_type< + Args + , graphs::graph + >::type + >::vertex_descriptor + > + , boost::mpl::true_ + , boost::mpl::false_ + > + { + }; +}; + +#include <boost/mpl/eval_if.hpp> + +struct graph_predicate +{ + template <typename T, typename Args> + struct apply + : boost::mpl::eval_if< + boost::is_convertible< + typename boost::graph_traits<T>::traversal_category + , boost::incidence_graph_tag + > + , boost::mpl::if_< + boost::is_convertible< + typename boost::graph_traits<T>::traversal_category + , boost::vertex_list_graph_tag + > + , boost::mpl::true_ + , boost::mpl::false_ + > + , boost::mpl::false_ + > + { + }; +}; + +#include <boost/property_map/property_map.hpp> +#include <boost/type_traits/is_same.hpp> + +struct color_map_predicate +{ + template <typename T, typename Args> + struct apply + : boost::mpl::if_< + boost::is_same< + typename boost::property_traits<T>::key_type + , typename boost::graph_traits< + typename boost::parameter::value_type< + Args + , graphs::graph + >::type + >::vertex_descriptor + > + , boost::mpl::true_ + , boost::mpl::false_ + > + { + }; +}; + +#include <boost/type_traits/is_integral.hpp> + +struct index_map_predicate +{ + template <typename T, typename Args> + struct apply + : boost::mpl::eval_if< + boost::is_integral< + typename boost::property_traits<T>::value_type + > + , boost::mpl::if_< + boost::is_same< + typename boost::property_traits<T>::key_type + , typename boost::graph_traits< + typename boost::parameter::value_type< + Args + , graphs::graph + >::type + >::vertex_descriptor + > + , boost::mpl::true_ + , boost::mpl::false_ + > + , boost::mpl::false_ + > + { + }; +}; + +#include <boost/graph/properties.hpp> +#include <vector> + +template <typename Size, typename IndexMap> +boost::iterator_property_map< + std::vector<boost::default_color_type>::iterator + , IndexMap + , boost::default_color_type + , boost::default_color_type& +>& + default_color_map(Size num_vertices, IndexMap const& index_map) +{ + static std::vector<boost::default_color_type> colors(num_vertices); + static boost::iterator_property_map< + std::vector<boost::default_color_type>::iterator + , IndexMap + , boost::default_color_type + , boost::default_color_type& + > m(colors.begin(), index_map); + return m; +} + +#include <boost/graph/depth_first_search.hpp> + +BOOST_PARAMETER_FUNCTION((void), depth_first_search, graphs, + (required + (graph, *(graph_predicate)) + ) + (optional + (visitor + , * // not easily checkable + , boost::dfs_visitor<>() + ) + (root_vertex + , *(vertex_descriptor_predicate) + , *vertices(graph).first + ) + (index_map + , *(index_map_predicate) + , get(boost::vertex_index, graph) + ) + (color_map + , *(color_map_predicate) + , default_color_map(num_vertices(graph), index_map) + ) + ) +) +{ +} + +#include <boost/core/lightweight_test.hpp> +#include <boost/graph/adjacency_list.hpp> +#include <utility> + +int main() +{ + typedef boost::adjacency_list< + boost::vecS + , boost::vecS + , boost::directedS + > G; + enum {u, v, w, x, y, z, N}; + typedef std::pair<std::size_t,std::size_t> E; + E edges[] = { + E(u, v), E(u, x), E(x, v), E(y, x), + E(v, y), E(w, y), E(w, z), E(z, z) + }; + G g(edges, edges + sizeof(edges) / sizeof(E), N); + + ::depth_first_search(g); + ::depth_first_search(g, _root_vertex = static_cast<std::size_t>(x)); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/required-parameters0.cpp b/src/boost/libs/parameter/test/literate/required-parameters0.cpp new file mode 100644 index 000000000..9bf59ce3a --- /dev/null +++ b/src/boost/libs/parameter/test/literate/required-parameters0.cpp @@ -0,0 +1,11 @@ + +#include <boost/parameter.hpp> + +BOOST_PARAMETER_NAME(graph) + +BOOST_PARAMETER_FUNCTION( + (void), f, tag, (required (graph, *) ) +) +{ +} + diff --git a/src/boost/libs/parameter/test/literate/static-member-functions0.cpp b/src/boost/libs/parameter/test/literate/static-member-functions0.cpp new file mode 100644 index 000000000..ce568285f --- /dev/null +++ b/src/boost/libs/parameter/test/literate/static-member-functions0.cpp @@ -0,0 +1,27 @@ + +#include <boost/parameter.hpp> +#include <iostream> + +using namespace boost::parameter; + +BOOST_PARAMETER_NAME(arg1) + +struct somebody +{ + BOOST_PARAMETER_MEMBER_FUNCTION( + (void), static f, tag, (optional (arg1,(int),0)) + ) + { + std::cout << arg1 << std::endl; + } +}; + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + somebody::f(); + somebody::f(4); + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/template-keywords0.cpp b/src/boost/libs/parameter/test/literate/template-keywords0.cpp new file mode 100644 index 000000000..9a10ce81e --- /dev/null +++ b/src/boost/libs/parameter/test/literate/template-keywords0.cpp @@ -0,0 +1,11 @@ + +#include <boost/parameter.hpp> + +namespace boost { namespace python { + + BOOST_PARAMETER_TEMPLATE_KEYWORD(class_type) + BOOST_PARAMETER_TEMPLATE_KEYWORD(base_list) + BOOST_PARAMETER_TEMPLATE_KEYWORD(held_type) + BOOST_PARAMETER_TEMPLATE_KEYWORD(copyable) +}} + diff --git a/src/boost/libs/parameter/test/literate/template-keywords1.cpp b/src/boost/libs/parameter/test/literate/template-keywords1.cpp new file mode 100644 index 000000000..a1adfa3e4 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/template-keywords1.cpp @@ -0,0 +1,17 @@ + +#include <boost/parameter.hpp> + +namespace boost { namespace python { + + namespace tag { + + struct class_type; // keyword tag type + } + + template <typename T> + struct class_type + : boost::parameter::template_keyword<boost::python::tag::class_type,T> + { + }; +}} + diff --git a/src/boost/libs/parameter/test/literate/top-level0.cpp b/src/boost/libs/parameter/test/literate/top-level0.cpp new file mode 100644 index 000000000..8a8e39f6f --- /dev/null +++ b/src/boost/libs/parameter/test/literate/top-level0.cpp @@ -0,0 +1,57 @@ + +#include <boost/parameter.hpp> + +namespace test { + + BOOST_PARAMETER_NAME(title) + BOOST_PARAMETER_NAME(width) + BOOST_PARAMETER_NAME(titlebar) + + BOOST_PARAMETER_FUNCTION((int), new_window, tag, + (required (title,*)(width,*)(titlebar,*)) + ) + { + return 0; + } + + BOOST_PARAMETER_TEMPLATE_KEYWORD(deleter) + BOOST_PARAMETER_TEMPLATE_KEYWORD(copy_policy) + + template <typename T> + struct Deallocate + { + }; + + struct DeepCopy + { + }; + + struct Foo + { + }; + + template <typename T, typename A0, typename A1> + struct smart_ptr + { + smart_ptr(test::Foo*) + { + } + }; +} + +#include <boost/core/lightweight_test.hpp> + +int main() +{ + char const* alert_s = "alert"; + int x = test::new_window(alert_s, test::_width=10, test::_titlebar=false); + test::Foo* foo = new test::Foo(); + test::smart_ptr< + test::Foo + , test::deleter<test::Deallocate<test::Foo> > + , test::copy_policy<test::DeepCopy> + > p(foo); + delete foo; + return boost::report_errors(); +} + diff --git a/src/boost/libs/parameter/test/literate/writing-the-function0.cpp b/src/boost/libs/parameter/test/literate/writing-the-function0.cpp new file mode 100644 index 000000000..6a05ea260 --- /dev/null +++ b/src/boost/libs/parameter/test/literate/writing-the-function0.cpp @@ -0,0 +1,45 @@ + +#include <boost/parameter/name.hpp> + +BOOST_PARAMETER_NAME(graph) +BOOST_PARAMETER_NAME(visitor) +BOOST_PARAMETER_NAME(root_vertex) +BOOST_PARAMETER_NAME(index_map) +BOOST_PARAMETER_NAME(in_out(color_map)) + +namespace boost { + + template <typename T = int> + struct dfs_visitor + { + }; + + int vertex_index = 0; +} + +#include <boost/parameter/preprocessor.hpp> + +namespace graphs { + + BOOST_PARAMETER_FUNCTION( + (void), // 1. parenthesized return type + depth_first_search, // 2. name of the function template + + tag, // 3. namespace of tag types + + (required (graph, *) ) // 4. one required parameter, and + + (optional // four optional parameters, with defaults + (visitor, *, boost::dfs_visitor<>()) + (root_vertex, *, *vertices(graph).first) + (index_map, *, get(boost::vertex_index,graph)) + (in_out(color_map), *, + default_color_map(num_vertices(graph), index_map) + ) + ) + ) + { + // ... body of function goes here... + // use graph, visitor, index_map, and color_map + } +} |