edouarda / brigand Goto Github PK
View Code? Open in Web Editor NEWInstant compile time C++ 11 metaprogramming library
License: Boost Software License 1.0
Instant compile time C++ 11 metaprogramming library
License: Boost Software License 1.0
It's a set, but there is no order, thus unordered_set. :)
shoudl support insert remove contains
idea is to have simialr thing than map but with a contains static member that return true_ if the key match
as in the title, should we have small scale, easy to grok and not compile-time heavy equivalent of fusion::vector and fusion::<some_algo> or are we diverging ?
without causing compiler error.
E.G : accessing a non existnet key in a brigand:map
void
and other non default constructible type cannot be key of map:
changing in map.hpp
template <typename T>
struct Type {};
// fastlane for constant amortized time
template <class T0>
struct map_impl<T0>
{
static typename T0::second_type at(Type<typename T0::first_type>);
template <typename U>
static no_such_type_ at(U) {}
};
// .. other fastlane
template <typename M, typename K>
struct lookup
{
using type = decltype(M::at(std::declval<Type<K>>())); // or using type = std::result_of_t<M::at(Type<K>)>;
};
and in at.hpp
template <typename T>
struct has_at_method
{
struct dummy {};
template <typename C, typename P>
static auto test(P*) -> decltype(static_cast<void>(C::at(std::declval<Type<P>>())) /*cast to handle comma operator */, std::true_type());
// previous false case + bool value
};
solves that.
Examples to do
brigand/algorithms/for_each.hpp(17): error C2062: type 'evil' unexp
And of course if I try to write Elements{}... I get internal compiler error :o
The following doesn't compile:
#include <brigand/sequences/list.hpp>
#include <brigand/algorithms/for_each.hpp>
struct evil
{
template< typename U > evil& operator()(U ) const { return *this; }
evil& operator, (int) { return *this; } // evel operator coma
};
void for_each_test()
{
brigand::for_each< brigand::list<char,short,int,double> >( evil{} );
}
fix is to change: return (void)std::initializer_list<int>{(std::ref(f)((Ts&&)a),0)...}, f;
into
return (void)std::initializer_list<int>{(static_cast<void>(std::ref(f)((Ts&&)a)),0)...}, f;
or
return (void)std::initializer_list<int>{(std::ref(f)((Ts&&)a), void(), 0)...}, f;
BTW, for (Ts&&) a
, g++ 4.9.2 produces following warning:
brigand/algorithms/for_each_args.hpp:15:64: warning: use of old-style cast [-Wold-style-cast]
quote turn template<typename...> struct F into a apply based metafunction class
The functions are not compliant with the placeholders model
MSVC 2013 really doesn't like the is_set implementation
Not really a issue, but due to static_assert
(and type
) in struct pair_wrapper
SFINAE doesn't occurs and following doesn't compile:
template <typename... Ts>
auto can_use_as_pair_impl(int)
-> decltype(typename brigand::as_pair<brigand::list<Ts...>>::type{}, std::true_type{});
template <typename... Ts>
std::false_type can_use_as_pair_impl(...);
template<typename... Ts>
using can_use_as_pair = decltype(can_use_as_pair_impl<Ts...>(0));
static_assert(std::is_same<std::true_type, can_use_as_pair<int, int>>::value, "error in brigand::as_pair");
static_assert(std::is_same<std::false_type, can_use_as_pair<int, int, int>>::value, "error in brigand::as_pair");
Simply put:
brigand::repeat<F,N,T> = brigand::repeat<F,N-1,F<T>>;
brigand::repeat<F,1,T> = F<T>;
brigand::repeat<F,0,T> = T;
and of course, fast-lane
Let's say i want to write compose<F,G> that gimme something akin to F<G> when applied to T.
or the negation fo a meta-function ?
Looks to me the syntax is not clear (see nope in all implementation).
#include
are invalid:
#include <brigand/algorithm/apply.hpp>
should be #include <brigand/algorithms/apply.hpp>
...)size.hpp
is in sequences
, not algorithm
.As there is no forward declaration for boost::variant
, boost/variant
is required before include brigand.hpp
:(.
Support for brigand::if_
And fix next/prev unit test
The proper order is Sequence, Functor and not Functor, Sequence
// this doesn't pass and should
static_assert(brigand::any<brigand::integral_list<int, 1, 1, 1, 1>>::value, "invalid any list");
// this pass and should not
static_assert(brigand::any<brigand::integral_list<int, 0, 0, 0, 0>>::value, "invalid any list");
Any is not !all
protect prevent substtution
I like the repetition in this issue ::issue
It can be rewritten as
template <class... Ts>
using last_element = decltype(type_<Ts>...)::type;
Maybe add a layer for a better message for 0-size.
Removes all elements satisfying specific criteria.
with xxx = tuple, pair, etc
We fixed some of those but or exampel i can pass transform to trasnform usign placeholders.
unpack < F, L < T... > > = apply < F,T... >
Hey guys, you've been many to have contributed to brigand, if you'd like to be listed as a contributor let me know here.
unique<T...> return true_ if all T... are different
Duplicates in map key are only handled within the fastlane.
so
using big_map = brigand::map<
brigand::pair<type_one, int>,
brigand::pair<type_two, type_one>,
brigand::pair<type_three, type_two>,
brigand::pair<type_four, type_three>,
brigand::pair<type_five, type_four>,
brigand::pair<type_six, type_five>,
brigand::pair<type_seven, type_six>,
brigand::pair<type_eight, type_seven>,
brigand::pair<type_one, type_eight> // Duplicate
>;
is a valid type whereas if we remove brigand::pair<type_eight, type_seven>,
, we correctly have compile error.
... with amortized O(1) at implementation + fast-lane for < 10 types
bind<F,....> takes a metafunction class and chanegs its parameters
range<int, 2, 5> = list<int_<2>, int_<3>, int_<4>>
lot of warning for no return statement in map.hpp (whereas definition is not needed)
brigand/sequences/map.hpp:20:37: warning: no return statement in function returning non-void [-Wreturn-type]
static no_such_type_ at(U) {}
just replace by
static no_such_type_ at(U);
brigand/algorithms/for_each_args.hpp:15:82: warning: use of old-style cast [-Wold-style-cast]
return (void)std::initializer_list{(static_cast(std::ref(f)((Ts&&)a)),0)...}, f;
Replace by std::forward<Ts>(a)
(or by static_cast<Ts&&>(a)
).
I think a static_assert on the size (ie you can't make a pair if your sequence is greater than 2) can help a lot in more complex metaprograms and it's very easy to do
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.