18 template<
class StdContainer>
19 int size(
const StdContainer& cont) {
return numeric_cast<
int>(cont.size()); }
41 {
return --it.base(); }
45 typename List::reverse_iterator
erase(List& list,
const typename List::reverse_iterator& iter)
52 typename List::iterator
eraseVal(List& list,
const typename List::value_type& val)
54 auto it =
std::find(list.begin(), list.end(), val);
55 if (it == list.end())
return list.end();
56 return list.erase(it);
60 template<
class List,
class T>
63 auto it = list.begin();
64 while((it =
std::find(it, list.end(), val)) != list.end())
69 template<
class MultiMap,
class Key,
class Val>
75 template<
class MultiSet,
class Val>
78 return honey::find(
range(set.equal_range(val)), [&](
auto& e) {
return e == val; });
82 template<
class Key,
class Value,
template<
class>
class Alloc>
83 using unordered_map = std::unordered_map<Key, Value, std::hash<Key>, std::equal_to<Key>, Alloc<pair<const Key, Value>>>;
85 template<
class Key,
class Value,
template<
class>
class Alloc>
86 using unordered_multimap = std::unordered_multimap<Key, Value, std::hash<Key>, std::equal_to<Key>, Alloc<pair<const Key, Value>>>;
88 template<
class Key,
template<
class>
class Alloc>
89 using unordered_set = std::unordered_set<Key, std::hash<Key>, std::equal_to<Key>, Alloc<Key>>;
91 template<
class Key,
template<
class>
class Alloc>
92 using unordered_multiset = std::unordered_multiset<Key, std::hash<Key>, std::equal_to<Key>, Alloc<Key>>;
100 #define PARAMT(It) , class T##It
101 #define PARAM(It) , T##It&& a##It
102 #define ARG(It) , forward<T##It>(a##It)
103 #define PLACE(It) , _##It
105 #define OP(It, ItMax) \
106 template<class Func ITERATE__(1,It,PARAMT)> \
107 auto operator()(Func&& f ITERATE__(1,It,PARAM)) -> \
108 decltype( bind(forward<Func>(f) ITERATE__(1,It,ARG) \
109 IFEQUAL(It,ItMax,,ITERATE__(1,PP_SUB(ItMax,It),PLACE))) ) \
111 return bind(forward<Func>(f) ITERATE__(1,It,ARG) \
112 IFEQUAL(It,ItMax,,ITERATE__(1,PP_SUB(ItMax,It),PLACE))); \
116 template<> struct bind_fill<It> { ITERATE1_(0, It, OP, It) }; \
137 template<
class Func,
class... Args>
141 return priv::bind_fill<mt::funcTraits<typename mt::removeRef<Func>::type>::arity>()(forward<Func>(f), forward<Args>(args)...);
148 template<
class T,
class Ptr = T*,
class ConstPtr = const T*>
157 operator T&() {
assert(_ptr);
return *_ptr; }
158 operator const T&()
const {
assert(_ptr);
return *_ptr; }
161 Ptr&
ptr() {
return _ptr; }
162 const ConstPtr&
ptr()
const {
return reinterpret_cast<const ConstPtr&
>(_ptr); }
172 template<class T, class Alloc = typename DefaultAllocator<T>::type>
178 recursive_wrap(T_&& t, Alloc a = Alloc()) : _ptr(new (a.allocate(1)) T(forward<T_>(t)), move(a)) {}
194 operator T&() {
assert(_ptr);
return *_ptr; }
195 operator const T&()
const {
assert(_ptr);
return *_ptr; }
198 const T*
ptr()
const {
return _ptr; }
205 template<
class Sub
class>
209 static bool hasInst(ios_base& ios) {
return ios.pword(pword); }
210 static Subclass&
inst(ios_base& ios)
212 if (!
hasInst(ios)) { ios.pword(pword) =
new Subclass(); ios.register_callback(&Manip::delete_, 0); }
213 return *
static_cast<Subclass*
>(ios.pword(pword));
217 static void delete_(ios_base::event ev, ios_base& ios,
int) {
if (ev == ios_base::erase_event)
honey::delete_(&
inst(ios)); }
218 static const int pword;
220 template<
class Sub
class>
const int Manip<Subclass>::pword = ios_base::xalloc();
223 template<
class Func,
class Tuple>
226 template<
class Func_,
class Tuple_>
229 template<
class Stream>
231 template<
class Stream>
234 template<
class Stream,
szt... Seq>
242 template<
class Func,
class... Args>
ManipFunc(Func_ &&f, Tuple_ &&args)
Definition: StdUtil.h:227
T * operator->()
Definition: StdUtil.h:155
auto manipFunc(Func &&f, Args &&...args)
Helper to create a manipulator that takes arguments. eg. A manip named 'foo': auto foo(int val) { ret...
Definition: StdUtil.h:243
recursive_wrap(Alloc a=Alloc())
Definition: StdUtil.h:176
bool operator==(const deref_wrap &rhs) const
Definition: StdUtil.h:159
recursive_wrap & operator=(const recursive_wrap &rhs)
Definition: StdUtil.h:185
Wraps a pointer so that it behaves similar to a reference.
Definition: StdUtil.h:149
recursive_wrap & operator=(recursive_wrap &rhs)
Definition: StdUtil.h:186
Allows for recursive type definitions, eg. class Object : vector>.
Definition: StdUtil.h:173
bool operator!=(const deref_wrap &rhs) const
Definition: StdUtil.h:160
T * ptr()
Get the internal pointer, may be null if wrapper was moved.
Definition: StdUtil.h:197
auto findVal(MultiMap &map, const Key &key, const Val &val) -> mt_iterOf(map)
Get iterator to key with value. Returns end if not found.
Definition: StdUtil.h:70
const ConstPtr & ptr() const
Definition: StdUtil.h:162
List::reverse_iterator erase(List &list, const typename List::reverse_iterator &iter)
Erase using reverse iterator. Returns reverse iterator to element after erased element.
Definition: StdUtil.h:45
Iter find(Range &&, Seqs &&..., Func &&pred)
Find an element in a series of sequences.
Wrapper around an iterator with tuple value type. When dereferenced returns I'th element.
Definition: Range.h:596
void delete_(T *&p)
Destruct object, free memory and set pointer to null.
Definition: Allocator.h:75
const T & operator*() const
Definition: StdUtil.h:191
static bool hasInst(ios_base &ios)
Definition: StdUtil.h:209
auto bind_fill(Func &&f, Args &&...args) -> decltype( priv::bind_fill< mt::funcTraits< typename mt::removeRef< Func >::type >::arity >()(forward< Func >(f), forward< Args >(args)...))
Version of bind that automatically fills in placeholders for unspecified arguments.
Definition: StdUtil.h:138
std::unordered_map< Key, Value, std::hash< Key >, std::equal_to< Key >, Alloc< pair< const Key, Value >>> unordered_map
std::unordered_map with custom allocator
Definition: StdUtil.h:83
std::enable_if< mt::isIterator< Iter1 >::value, Range_< Iter1, Iter2 > >::type range(Iter1 &&first, Iter2 &&last)
Range from iterators [first, last)
Definition: Range.h:116
friend Stream & operator>>(Stream &is, const ManipFunc &manip)
Definition: StdUtil.h:232
T * operator->()
Definition: StdUtil.h:192
Helper to create a manipulator that takes arguments.
Definition: StdUtil.h:224
auto keys(Range &&range) -> Range_< TupleIter< mt_iterOf(range), 0 >, TupleIter< mt_iterOf(range), 0 >>
Create a range over the keys of a map or map iterator range.
Definition: StdUtil.h:23
T & operator*()
Definition: StdUtil.h:153
#define mt_iterOf(Range)
iterOf for values
Definition: Range.h:33
recursive_wrap & operator=(T_ &&t)
Definition: StdUtil.h:184
friend Stream & operator<<(Stream &os, const ManipFunc &manip)
Definition: StdUtil.h:230
static Subclass & inst(ios_base &ios)
Definition: StdUtil.h:210
Get function type traits.
Definition: Meta.h:227
#define assert(...)
Forwards to assert_#args. See assert_1(), assert_2().
Definition: Debug.h:24
Ptr & ptr()
Definition: StdUtil.h:161
recursive_wrap(recursive_wrap &rhs)
Definition: StdUtil.h:180
Func f
Definition: StdUtil.h:237
void eraseVals(List &list, const T &val)
Erase all occurrences of value.
Definition: StdUtil.h:61
const T * ptr() const
Definition: StdUtil.h:198
std::unordered_multiset< Key, std::hash< Key >, std::equal_to< Key >, Alloc< Key >> unordered_multiset
std::unordered_multiset with custom allocator
Definition: StdUtil.h:92
size_t szt
Size type, shorthand for size_t.
Definition: Core.h:90
auto values(Range &&range) -> Range_< TupleIter< mt_iterOf(range), 1 >, TupleIter< mt_iterOf(range), 1 >>
Create a range over the values of a map or map iterator range.
Definition: StdUtil.h:30
auto reverseIterToForward(Iter &&it) -> typename mt::removeRef< decltype(--it.base())>::type
Convert reverse iterator to forward iterator.
Definition: StdUtil.h:40
std::unordered_multimap< Key, Value, std::hash< Key >, std::equal_to< Key >, Alloc< pair< const Key, Value >>> unordered_multimap
std::unordered_multimap with custom allocator
Definition: StdUtil.h:86
#define ITERATE(Min, Max, Func)
Iterate calling Func(It, Args...) over range [Min, Max], where Min >= 0 and Max <= ITERATE_MAX...
Definition: Preprocessor.h:58
T & operator*()
Get the wrapped object.
Definition: StdUtil.h:190
const T * operator->() const
Definition: StdUtil.h:193
Iterator range. See range(Iter1&&, Iter2&&) to create.
Definition: Range.h:88
int size(const StdContainer &cont)
Safely get the size of a std container as a signed integer.
Definition: StdUtil.h:19
List::iterator eraseVal(List &list, const typename List::value_type &val)
Erase first occurrence of value. Returns iterator to next element after the erased element...
Definition: StdUtil.h:52
recursive_wrap(T_ &&t, Alloc a=Alloc())
Definition: StdUtil.h:178
const T * operator->() const
Definition: StdUtil.h:156
Base class to hold iostream manipulator state. Inherit from this class and call Subclass::inst(ios) t...
Definition: StdUtil.h:206
Tuple args
Definition: StdUtil.h:238
recursive_wrap(const recursive_wrap &rhs)
Definition: StdUtil.h:179
const T & operator*() const
Definition: StdUtil.h:154
deref_wrap(Ptr ptr=nullptr)
Definition: StdUtil.h:152
std::unordered_set< Key, std::hash< Key >, std::equal_to< Key >, Alloc< Key >> unordered_set
std::unordered_set with custom allocator
Definition: StdUtil.h:89
Pointer to a unique, non-shared, object. Finalizer is run upon destruction (deletes object by default...
Definition: SharedPtr.h:164
recursive_wrap & operator=(recursive_wrap &&rhs)
Definition: StdUtil.h:187
Global Honeycomb namespace.
void apply(Stream &ios, mt::idxseq< Seq... >) const
Definition: StdUtil.h:235
recursive_wrap(recursive_wrap &&rhs)
Definition: StdUtil.h:181
OutSeq && map(Range &&, Seqs &&..., OutSeq &&, Func &&)
Transform a series of sequences into an output.