Skip to content

Commit

Permalink
[ext/mpl] MPL vectors are not Sequences anymore
Browse files Browse the repository at this point in the history
  • Loading branch information
ldionne committed Feb 27, 2015
1 parent d7f5862 commit 7e2bcdf
Show file tree
Hide file tree
Showing 16 changed files with 249 additions and 313 deletions.
1 change: 1 addition & 0 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ file(GLOB_RECURSE BOOST_HANA_EXAMPLES_REQUIRING_BOOST
"ext/boost/*.cpp"
"record.macros.cpp"
"tutorial/type_computations.cpp"
"tutorial/mpl_cheatsheet.cpp"
"mini_mpl.cpp")
list(APPEND BOOST_HANA_FILES_REQUIRING_BOOST ${BOOST_HANA_EXAMPLES_REQUIRING_BOOST})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ using namespace boost::hana;
namespace mpl = boost::mpl;


int main() {

{

//! [constant]
static_assert(value(mpl::integral_c<int, 3>{}) == 3, "");

BOOST_HANA_CONSTANT_CHECK(equal(mpl::integral_c<int, 3>{}, mpl::int_<3>{}));
BOOST_HANA_CONSTANT_CHECK(equal(mpl::integral_c<int, 3>{}, mpl::long_<3>{}));
BOOST_HANA_CONSTANT_CHECK(not_equal(mpl::integral_c<int, 3>{}, mpl::int_<0>{}));
//! [constant]

}

int main() { }
}
81 changes: 81 additions & 0 deletions example/ext/boost/mpl/vector.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
@copyright Louis Dionne 2015
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/

#include <boost/hana/assert.hpp>
#include <boost/hana/ext/boost/mpl/vector.hpp>
#include <boost/hana/ext/std/integral_constant.hpp>
#include <boost/hana/maybe.hpp>
#include <boost/hana/type.hpp>

#include <boost/mpl/vector.hpp>
#include <type_traits>
using namespace boost::hana;
namespace mpl = boost::mpl;


int main() {

{

//! [comparable]
BOOST_HANA_CONSTANT_CHECK(
equal(mpl::vector2<int, char>{}, mpl::vector<int, char>{})
);
BOOST_HANA_CONSTANT_CHECK(
not_equal(mpl::vector2<int, char>{}, mpl::vector<int, char, float>{})
);
//! [comparable]

}{

//! [foldable]
auto types = mpl::vector<long, float, short, float, long, long double>{};
auto number_of_floats = foldl(types, int_<0>, [](auto count, auto t) {
return if_(trait<std::is_floating_point>(t),
count + int_<1>,
count
);
});

BOOST_HANA_CONSTANT_CHECK(number_of_floats == int_<3>);
//! [foldable]

}{

//! [iterable]
BOOST_HANA_CONSTANT_CHECK(head(mpl::vector<int, char, void>{}) == type<int>);

BOOST_HANA_CONSTANT_CHECK(equal(
tail(mpl::vector<int, char, void>{}),
mpl::vector<char, void>{}
));

BOOST_HANA_CONSTANT_CHECK(equal(
drop_while(mpl::vector<float, double const, int, float&>{},
trait<std::is_floating_point>),
mpl::vector<int, float&>{}
));
//! [iterable]

}{

//! [searchable]
BOOST_HANA_CONSTANT_CHECK(
find(mpl::vector<int, float, char const*>{}, equal.to(type<float>))
==
just(type<float>)
);

BOOST_HANA_CONSTANT_CHECK(
lookup(mpl::vector<int, float, char const*>{}, type<void>)
==
nothing
);
//! [searchable]

}

}
18 changes: 0 additions & 18 deletions example/ext/boost/mpl/vector/comparable.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions example/ext/boost/mpl/vector/functor.cpp

This file was deleted.

30 changes: 0 additions & 30 deletions example/ext/boost/mpl/vector/iterable.cpp

This file was deleted.

32 changes: 0 additions & 32 deletions example/ext/boost/mpl/vector/list.cpp

This file was deleted.

File renamed without changes.
10 changes: 10 additions & 0 deletions include/boost/hana.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ namespace boost { namespace hana {
//! @defgroup group-core Core
//! Core utilities of the library.

//! @defgroup group-ext External adapters
//! Adapters for external libraries.

//! @defgroup group-config Configuration options
//! Configurable options to tweak the global behavior of the library.

Expand Down Expand Up @@ -789,6 +792,8 @@ the library was also intentionally kept simple, because we all love simplicity.
This subdirectory contains the forward declaration of every concept
and data type in the library. Basically, `boost/hana/fwd/[XXX].hpp`
is the forward declaration for the concept or data type named `XXX`.
Also note that forward declarations for headers in `boost/hana/ext/`
are not provided.
- `boost/hana/functional/`\n
This subdirectory contains various function objects that are often useful,
Expand Down Expand Up @@ -858,6 +863,11 @@ The structure of the reference (available in the menu to the left) goes as
also documents the methods tied to that data type but not to any concept,
for example `make<Tuple>`.
- @ref group-ext\n
Documentation for all the adapters for external libraries. Basically, we
assign a data type to some objects in external libraries and we document
them as if they were normal data types provided by Hana.
- @ref group-config\n
Macros that can be used to tweak the global behavior of the library.
Expand Down
33 changes: 30 additions & 3 deletions include/boost/hana/ext/boost/mpl/integral_c.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ Distributed under the Boost Software License, Version 1.0.
#ifndef BOOST_HANA_EXT_BOOST_MPL_INTEGRAL_C_HPP
#define BOOST_HANA_EXT_BOOST_MPL_INTEGRAL_C_HPP

#include <boost/hana/fwd/ext/boost/mpl/integral_c.hpp>

#include <boost/hana/comparable.hpp>
#include <boost/hana/constant.hpp>
#include <boost/hana/core/convert.hpp>
#include <boost/hana/core/datatype.hpp>
#include <boost/hana/core/is_a.hpp>
#include <boost/hana/core/models.hpp>
#include <boost/hana/core/when.hpp>
#include <boost/hana/detail/std/is_integral.hpp>
#include <boost/hana/detail/std/is_same.hpp>
#include <boost/hana/enumerable.hpp>
#include <boost/hana/group.hpp>
#include <boost/hana/integral_domain.hpp>
Expand All @@ -28,9 +27,37 @@ Distributed under the Boost Software License, Version 1.0.
#include <boost/hana/ring.hpp>

#include <boost/mpl/integral_c.hpp>
#include <boost/mpl/integral_c_tag.hpp>


namespace boost { namespace hana {
namespace ext { namespace boost { namespace mpl {
//! @ingroup group-ext
//! Adapter for IntegralConstants from the Boost.MPL.
//!
//! Provided models
//! ---------------
//! 1. `Constant`\n
//! As Constants holding an integral type, `IntegralC`s are models
//! not only of Constant, but also all the other concepts that are
//! provided for Constants of an integral type.
//! @snippet example/ext/boost/mpl/integral_c.cpp constant
template <typename T>
struct IntegralC { using value_type = T; };
}}}

template <typename T>
struct datatype<T, when<
detail::std::is_same<
typename T::tag,
::boost::mpl::integral_c_tag
>::value
>> {
using type = ext::boost::mpl::IntegralC<
typename datatype<typename T::value_type>::type
>;
};

//////////////////////////////////////////////////////////////////////////
// Constant
//////////////////////////////////////////////////////////////////////////
Expand Down

0 comments on commit 7e2bcdf

Please sign in to comment.