Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add metafunction boost::parameter::is_argument_pack #27

Merged
merged 2 commits into from Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
140 changes: 93 additions & 47 deletions doc/html/reference.html

Large diffs are not rendered by default.

34 changes: 27 additions & 7 deletions doc/reference.rst
Expand Up @@ -166,20 +166,19 @@ intended argument type
Concepts
========

This section describes the generic type concepts_ used by the Parameter
This section describes the generic type concepts used by the Parameter
library.

.. _concepts: http://www.boost.org/more/generic_programming.html#concept

|ArgumentPack|
--------------

An |ArgumentPack| is a collection of |tagged reference|\ s to the actual
arguments passed to a function. Every |ArgumentPack| is also a valid MPL
|ForwardSequence|__ consisting of the |keyword tag type|\ s in its
|tagged reference|\ s.
arguments passed to a function. Every |ArgumentPack| is also a valid `MPL
Forward Sequence`_ and `MPL Associative Sequence`_ consisting of the |keyword
tag type|\ s in its |tagged reference|\ s.

__ ../../../mpl/doc/refmanual/forward-sequence.html
.. _`MPL Forward Sequence`: ../../../mpl/doc/refmanual/forward-sequence.html
.. _`MPL Associative Sequence`: ../../../mpl/doc/refmanual/associative-sequence.html

Requirements
............
Expand Down Expand Up @@ -299,6 +298,8 @@ __ ../../../../boost/parameter/keyword.hpp
template <typename Tag>
struct keyword
{
typedef Tag tag;

template <typename T>
typename boost::`enable_if`_<
typename boost::mpl::`eval_if_`_<
Expand Down Expand Up @@ -526,6 +527,8 @@ __ ../../../../boost/parameter/keyword.hpp
template <typename Tag>
struct keyword
{
typedef Tag tag;

template <typename T>
typename boost::`enable_if`_<
typename boost::mpl::`eval_if_`_<
Expand Down Expand Up @@ -1106,6 +1109,23 @@ exists, returns ``D``. Equivalent to::

… when ``D`` is not a reference type.

``is_argument_pack``
--------------------

:Defined in: `boost/parameter/is_argument_pack.hpp`__

__ ../../../../boost/parameter/is_argument_pack.hpp

.. parsed-literal::

template <typename T>
struct is_argument_pack // : mpl::true_ or mpl::false_
{
};

:Returns: ``mpl::true_`` if ``T`` is a model of |ArgumentPack|_,
``mpl::false_`` otherwise.

//////////////////////////////////////////////////////////////////////////////

Code Generation Macros
Expand Down
1 change: 1 addition & 0 deletions include/boost/parameter.hpp
Expand Up @@ -9,6 +9,7 @@
#define BOOST_PARAMETER_050401_HPP

#include <boost/parameter/parameters.hpp>
#include <boost/parameter/is_argument_pack.hpp>
#include <boost/parameter/required.hpp>
#include <boost/parameter/optional.hpp>
#include <boost/parameter/deduced.hpp>
Expand Down
135 changes: 129 additions & 6 deletions include/boost/parameter/aux_/arg_list.hpp
Expand Up @@ -857,7 +857,7 @@ namespace boost { namespace parameter { namespace aux {
};
}}} // namespace boost::parameter::aux

#include <boost/mpl/begin.hpp>
#include <boost/mpl/begin_end_fwd.hpp>

// MPL sequence support
namespace boost { namespace mpl {
Expand All @@ -871,11 +871,6 @@ namespace boost { namespace mpl {
typedef ::boost::parameter::aux::arg_list_iterator<S> type;
};
};
}} // namespace boost::mpl

#include <boost/mpl/end.hpp>

namespace boost { namespace mpl {

template <>
struct end_impl< ::boost::parameter::aux::arg_list_tag>
Expand All @@ -890,5 +885,133 @@ namespace boost { namespace mpl {
};
}} // namespace boost::mpl

#include <boost/mpl/has_key_fwd.hpp>
#include <boost/mpl/find.hpp>

namespace boost { namespace mpl {

template <>
struct has_key_impl< ::boost::parameter::aux::arg_list_tag>
{
template <typename ArgList, typename Keyword>
struct apply
{
typedef typename ::boost::mpl::if_<
::boost::is_same<
typename ::boost::mpl::find<ArgList,Keyword>::type
, ::boost::parameter::aux::arg_list_iterator<
::boost::parameter::aux::empty_arg_list
>
>
, ::boost::mpl::false_
, ::boost::mpl::true_
>::type type;
};
};
}} // namespace boost::mpl

#include <boost/mpl/count_fwd.hpp>
#include <boost/mpl/int.hpp>

namespace boost { namespace mpl {

template <>
struct count_impl< ::boost::parameter::aux::arg_list_tag>
{
template <typename ArgList, typename Keyword>
struct apply
{
typedef typename ::boost::mpl::if_<
::boost::is_same<
typename ::boost::mpl::find<ArgList,Keyword>::type
, ::boost::parameter::aux::arg_list_iterator<
::boost::parameter::aux::empty_arg_list
>
>
, ::boost::mpl::int_<0>
, ::boost::mpl::int_<1>
>::type type;
};
};
}} // namespace boost::mpl

#include <boost/mpl/key_type_fwd.hpp>

namespace boost { namespace mpl {

template <>
struct key_type_impl< ::boost::parameter::aux::arg_list_tag>
{
template <typename ArgList, typename Keyword>
struct apply
{
typedef typename ::boost::mpl::eval_if<
::boost::is_same<
typename ::boost::mpl::find<ArgList,Keyword>::type
, ::boost::parameter::aux::arg_list_iterator<
::boost::parameter::aux::empty_arg_list
>
>
, void
, ::boost::mpl::identity<Keyword>
>::type type;
};
};
}} // namespace boost::mpl

#include <boost/mpl/value_type_fwd.hpp>

namespace boost { namespace mpl {

template <>
struct value_type_impl< ::boost::parameter::aux::arg_list_tag>
: ::boost::mpl::key_type_impl< ::boost::parameter::aux::arg_list_tag>
{
};
}} // namespace boost::mpl

#include <boost/mpl/at_fwd.hpp>

namespace boost { namespace mpl {

template <>
struct at_impl< ::boost::parameter::aux::arg_list_tag>
: ::boost::mpl::key_type_impl< ::boost::parameter::aux::arg_list_tag>
{
};
}} // namespace boost::mpl

#include <boost/mpl/order_fwd.hpp>
#include <boost/mpl/void.hpp>
#include <boost/mpl/distance.hpp>

namespace boost { namespace mpl {

template <>
struct order_impl< ::boost::parameter::aux::arg_list_tag>
{
template <typename ArgList, typename Keyword>
struct apply
{
typedef typename ::boost::mpl::find<ArgList,Keyword>::type Itr;
typedef typename ::boost::mpl::eval_if<
::boost::is_same<
Itr
, ::boost::parameter::aux::arg_list_iterator<
::boost::parameter::aux::empty_arg_list
>
>
, ::boost::mpl::identity< ::boost::mpl::void_>
, ::boost::mpl::distance<
Itr
, ::boost::parameter::aux::arg_list_iterator<
::boost::parameter::aux::empty_arg_list
>
>
>::type type;
};
};
}} // namespace boost::mpl

#endif // include guard

29 changes: 29 additions & 0 deletions include/boost/parameter/is_argument_pack.hpp
@@ -0,0 +1,29 @@
// Copyright Cromwell D. Enage 2018.
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#ifndef BOOST_PARAMETER_IS_ARGUMENT_PACK_HPP
#define BOOST_PARAMETER_IS_ARGUMENT_PACK_HPP

#include <boost/parameter/aux_/is_tagged_argument.hpp>
#include <boost/parameter/aux_/arg_list.hpp>
#include <boost/mpl/bool.hpp>
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_base_of.hpp>

namespace boost { namespace parameter {

template <typename T>
struct is_argument_pack
: ::boost::mpl::if_<
::boost::is_base_of< ::boost::parameter::aux::empty_arg_list,T>
, ::boost::mpl::true_
, ::boost::parameter::aux::is_tagged_argument<T>
>::type
{
};
}}

#endif // include guard

4 changes: 4 additions & 0 deletions include/boost/parameter/keyword.hpp
Expand Up @@ -43,6 +43,8 @@ namespace boost { namespace parameter {
template <typename Tag>
struct keyword
{
typedef Tag tag;

template <typename T>
inline typename ::boost::lazy_enable_if<
typename ::boost::mpl::eval_if<
Expand Down Expand Up @@ -344,6 +346,8 @@ namespace boost { namespace parameter {
template <typename Tag>
struct keyword
{
typedef Tag tag;

template <typename T>
#if defined(BOOST_NO_SFINAE)
inline typename ::boost::parameter::aux::tag<Tag,T const&>::type
Expand Down