Audacity  2.2.2
MemoryX.h
Go to the documentation of this file.
1 #ifndef __AUDACITY_MEMORY_X_H__
2 #define __AUDACITY_MEMORY_X_H__
3 
4 // C++ standard header <memory> with a few extensions
5 #include <memory>
6 #include <cstdlib> // Needed for free.
7 #ifndef safenew
8 #define safenew new
9 #endif
10 
11 // Conditional compilation switch indicating whether to rely on
12 // std:: containers knowing about rvalue references
13 #undef __AUDACITY_OLD_STD__
14 
15 
16 #include <functional>
17 
18 #if !(_MSC_VER >= 1800 || __cplusplus >= 201402L)
19 /* replicate the very useful C++14 make_unique for those build environments
20 that don't implement it yet.
21 typical useage:
22 auto p = std::make_unique<Myclass>(ctorArg1, ctorArg2, ... ctorArgN);
23 p->DoSomething();
24 auto q = std::make_unique<Myclass[]>(count);
25 q[0].DoSomethingElse();
26 
27 The first hides naked NEW and DELETE from the source code.
28 The second hides NEW[] and DELETE[]. Both of course ensure destruction if
29 you don't use something like std::move(p) or q.release(). Both expressions require
30 that you identify the type only once, which is brief and less error prone.
31 
32 (Whereas this omission of [] might invite a runtime error:
33 std::unique_ptr<Myclass> q { safenew Myclass[count] }; )
34 
35 Some C++11 tricks needed here are (1) variadic argument lists and
36 (2) making the compile-time dispatch work correctly. You can't have
37 a partially specialized template function, but you get the effect of that
38 by other metaprogramming means.
39 */
40 
41 namespace std {
42  // For overloading resolution
43  template <typename X> struct __make_unique_result {
44  using scalar_case = unique_ptr<X>;
45  };
46 
47  // Partial specialization of the struct for array case
48  template <typename X> struct __make_unique_result<X[]> {
49  using array_case = unique_ptr<X[]>;
50  using element = X;
51  };
52 
53  // Now the scalar version of unique_ptr
54  template<typename X, typename... Args> inline
56  make_unique(Args&&... args)
57  {
59  { safenew X(forward<Args>(args)...) };
60  }
61 
62  // Now the array version of unique_ptr
63  // The compile-time dispatch trick is that the non-existence
64  // of the scalar_case type makes the above overload
65  // unavailable when the template parameter is explicit
66  template<typename X> inline
67  typename __make_unique_result<X>::array_case
68  make_unique(size_t count)
69  {
70  return typename __make_unique_result<X>::array_case
71  { safenew typename __make_unique_result<X>::element[count] };
72  }
73 }
74 #endif
75 
76 /*
77  * ArrayOf<X>
78  * Not to be confused with std::array (which takes a fixed size) or std::vector
79  * This maintains a pointer allocated by NEW X[]. It's cheap: only one pointer,
80  * with no size and capacity information for resizing as for vector, and if X is
81  * a built-in numeric or pointer type, by default there is no zero filling at
82  * allocation time.
83  */
84 
85 template<typename X>
86 class ArrayOf : public std::unique_ptr<X[]>
87 {
88 public:
89  ArrayOf() {}
90 
91  template<typename Integral>
92  explicit ArrayOf(Integral count, bool initialize = false)
93  {
94  static_assert(std::is_unsigned<Integral>::value, "Unsigned arguments only");
95  reinit(count, initialize);
96  }
97 
98  //ArrayOf(const ArrayOf&) PROHIBITED;
99  ArrayOf(const ArrayOf&) = delete;
100  ArrayOf(ArrayOf&& that)
101  : std::unique_ptr < X[] >
102  (std::move((std::unique_ptr < X[] >&)(that)))
103  {
104  }
106  {
107  std::unique_ptr<X[]>::operator=(std::move(that));
108  return *this;
109  }
110  ArrayOf& operator= (std::unique_ptr<X[]> &&that)
111  {
112  std::unique_ptr<X[]>::operator=(std::move(that));
113  return *this;
114  }
115 
116  template< typename Integral >
117  void reinit(Integral count,
118  bool initialize = false)
119  {
120  static_assert(std::is_unsigned<Integral>::value, "Unsigned arguments only");
121  if (initialize)
122  // Initialize elements (usually, to zero for a numerical type)
123  std::unique_ptr<X[]>::reset(safenew X[count]{});
124  else
125  // Avoid the slight initialization overhead
126  std::unique_ptr<X[]>::reset(safenew X[count]);
127  }
128 };
129 
130 /*
131  * ArraysOf<X>
132  * This simplifies arrays of arrays, each array separately allocated with NEW[]
133  * But it might be better to use std::Array<ArrayOf<X>, N> for some small constant N
134  * Or use just one array when sub-arrays have a common size and are not large.
135  */
136 template<typename X>
137 class ArraysOf : public ArrayOf<ArrayOf<X>>
138 {
139 public:
140  ArraysOf() {}
141 
142  template<typename Integral>
143  explicit ArraysOf(Integral N)
144  : ArrayOf<ArrayOf<X>>( N )
145  {}
146 
147  template<typename Integral1, typename Integral2 >
148  ArraysOf(Integral1 N, Integral2 M, bool initialize = false)
149  : ArrayOf<ArrayOf<X>>( N )
150  {
151  static_assert(std::is_unsigned<Integral1>::value, "Unsigned arguments only");
152  static_assert(std::is_unsigned<Integral2>::value, "Unsigned arguments only");
153  for (size_t ii = 0; ii < N; ++ii)
154  (*this)[ii] = ArrayOf<X>{ M, initialize };
155  }
156 
157  //ArraysOf(const ArraysOf&) PROHIBITED;
158  ArraysOf(const ArraysOf&) =delete;
160  {
161  ArrayOf<ArrayOf<X>>::operator=(std::move(that));
162  return *this;
163  }
164 
165  template< typename Integral >
166  void reinit(Integral count)
167  {
168  ArrayOf<ArrayOf<X>>::reinit( count );
169  }
170 
171  template< typename Integral >
172  void reinit(Integral count, bool initialize)
173  {
174  ArrayOf<ArrayOf<X>>::reinit( count, initialize );
175  }
176 
177  template<typename Integral1, typename Integral2 >
178  void reinit(Integral1 countN, Integral2 countM, bool initialize = false)
179  {
180  static_assert(std::is_unsigned<Integral1>::value, "Unsigned arguments only");
181  static_assert(std::is_unsigned<Integral2>::value, "Unsigned arguments only");
182  reinit(countN, false);
183  for (size_t ii = 0; ii < countN; ++ii)
184  (*this)[ii].reinit(countM, initialize);
185  }
186 };
187 
188 /*
189  * template class Maybe<X>
190  * Can be used for monomorphic objects that are stack-allocable, but only conditionally constructed.
191  * You might also use it as a member.
192  * Initialize with create(), then use like a smart pointer,
193  * with *, ->, get(), reset(), or in if()
194  */
195 
196 // Placement-NEW is used below, and that does not cooperate with the DEBUG_NEW for Visual Studio
197 #ifdef _DEBUG
198 #ifdef _MSC_VER
199 #undef new
200 #endif
201 #endif
202 
203 template<typename X>
204 class Maybe {
205 public:
206 
207  // Construct as NULL
208  Maybe() {}
209 
210  // Supply the copy and move, so you might use this as a class member too
211  Maybe(const Maybe &that)
212  {
213  if (that.get())
214  create(*that);
215  }
216 
217  Maybe& operator= (const Maybe &that)
218  {
219  if (this != &that) {
220  if (that.get())
221  create(*that);
222  else
223  reset();
224  }
225  return *this;
226  }
227 
228  Maybe(Maybe &&that)
229  {
230  if (that.get())
231  create(::std::move(*that));
232  }
233 
235  {
236  if (this != &that) {
237  if (that.get())
238  create(::std::move(*that));
239  else
240  reset();
241  }
242  return *this;
243  }
244 
245  // Make an object in the buffer, passing constructor arguments,
246  // but destroying any previous object first
247  // Note that if constructor throws, we remain in a consistent
248  // NULL state -- giving exception safety but only weakly
249  // (previous value was lost if present)
250  template<typename... Args>
251  void create(Args&&... args)
252  {
253  // Lose any old value
254  reset();
255  // Create NEW value
256  pp = safenew(address()) X(std::forward<Args>(args)...);
257  }
258 
259  // Destroy any object that was built in it
261  {
262  reset();
263  }
264 
265  // Pointer-like operators
266 
267  // Dereference, with the usual bad consequences if NULL
268  X &operator* () const
269  {
270  return *pp;
271  }
272 
273  X *operator-> () const
274  {
275  return pp;
276  }
277 
278  X* get() const
279  {
280  return pp;
281  }
282 
283  void reset()
284  {
285  if (pp)
286  pp->~X(), pp = nullptr;
287  }
288 
289  // So you can say if(ptr)
290  explicit operator bool() const
291  {
292  return pp != nullptr;
293  }
294 
295 private:
296  X* address()
297  {
298  return reinterpret_cast<X*>(&storage);
299  }
300 
301  // Data
302 #if 0
303  typename ::std::aligned_storage<
304  sizeof(X)
305  // , alignof(X) // Not here yet in all compilers
306  >::type storage{};
307 #else
308  union {
309  double d;
310  char storage[sizeof(X)];
311  };
312 #endif
313  X* pp{ nullptr };
314 };
315 
316 // Restore definition of debug new
317 #ifdef _DEBUG
318 #ifdef _MSC_VER
319 #undef THIS_FILE
320 static char*THIS_FILE = __FILE__;
321 #define new new(_NORMAL_BLOCK, THIS_FILE, __LINE__)
322 #endif
323 #endif
324 
325 // Frequently, we need to use a vector or list of unique_ptr if we can, but default
326 // to shared_ptr if we can't (because containers know how to copy elements only,
327 // not move them).
328 #ifdef __AUDACITY_OLD_STD__
329 template<typename T> using movable_ptr = std::shared_ptr<T>;
330 template<typename T, typename Deleter> using movable_ptr_with_deleter_base = std::shared_ptr<T>;
331 #else
332 template<typename T> using movable_ptr = std::unique_ptr<T>;
333 template<typename T, typename Deleter> using movable_ptr_with_deleter_base = std::unique_ptr<T, Deleter>;
334 #endif
335 
336 template<typename T, typename... Args>
337 inline movable_ptr<T> make_movable(Args&&... args)
338 {
339  return std::
340 #ifdef __AUDACITY_OLD_STD__
341  make_shared
342 #else
343  make_unique
344 #endif
345  <T>(std::forward<Args>(args)...);
346 }
347 
348 template<typename T, typename Deleter> class movable_ptr_with_deleter
349  : public movable_ptr_with_deleter_base < T, Deleter >
350 {
351 public:
352  // Do not expose a constructor that takes only a pointer without deleter
353  // That is important when implemented with shared_ptr
355  movable_ptr_with_deleter(T* p, const Deleter &d)
356  : movable_ptr_with_deleter_base<T, Deleter>( p, d ) {}
357 
358 #ifdef __AUDACITY_OLD_STD__
359 
360  // copy
362  : movable_ptr_with_deleter_base < T, Deleter > ( that )
363  {
364  }
365 
367  {
368  if (this != &that) {
370  that;
371  }
372  return *this;
373  }
374 
375 #else
376 
377  // move
379  : movable_ptr_with_deleter_base < T, Deleter > ( std::move(that) )
380  {
381  }
382 
384  {
385  if (this != &that) {
387  std::move(that);
388  }
389  return *this;
390  }
391 
392 #endif
393 };
394 
395 template<typename T, typename Deleter, typename... Args>
397 make_movable_with_deleter(const Deleter &d, Args&&... args)
398 {
399  return movable_ptr_with_deleter<T, Deleter>(safenew T(std::forward<Args>(args)...), d);
400 }
401 
402 /*
403  * A deleter for pointers obtained with malloc
404  */
405 struct freer { void operator() (void *p) const { free(p); } };
406 
407 /*
408  * A useful alias for holding the result of malloc
409  */
410 template< typename T >
411 using MallocPtr = std::unique_ptr< T, freer >;
412 
413 /*
414  * A useful alias for holding the result of strup and similar
415  */
416 template <typename Character = char>
417 using MallocString = std::unique_ptr< Character[], freer >;
418 
419 /*
420  * A deleter class to supply the second template parameter of unique_ptr for
421  * classes like wxWindow that should be sent a message called Destroy rather
422  * than be deleted directly
423  */
424 template <typename T>
425 struct Destroyer {
426  void operator () (T *p) const { if (p) p->Destroy(); }
427 };
428 
429 /*
430  * a convenience for using Destroyer
431  */
432 template <typename T>
433 using Destroy_ptr = std::unique_ptr<T, Destroyer<T>>;
434 
435 /*
436  * "finally" as in The C++ Programming Language, 4th ed., p. 358
437  * Useful for defining ad-hoc RAII actions.
438  * typical usage:
439  * auto cleanup = finally([&]{ ... code; ... });
440  */
441 
442 // Construct this from any copyable function object, such as a lambda
443 template <typename F>
444 struct Final_action {
445  Final_action(F f) : clean( f ) {}
447  F clean;
448 };
449 
450 // Function template with type deduction lets you construct Final_action
451 // without typing any angle brackets
452 template <typename F>
453 Final_action<F> finally (F f)
454 {
455  return Final_action<F>(f);
456 }
457 
458 #include <wx/utils.h> // for wxMin, wxMax
459 #include <algorithm>
460 
461 /*
462  * Set a variable temporarily in a scope
463  */
464 template< typename T >
465 struct RestoreValue {
467  void operator () ( T *p ) const { if (p) *p = oldValue; }
468 };
469 
470 template< typename T >
471 class ValueRestorer : public std::unique_ptr< T, RestoreValue<T> >
472 {
473  using std::unique_ptr< T, RestoreValue<T> >::reset; // make private
474  // But release() remains public and can be useful to commit a changed value
475 public:
476  explicit ValueRestorer( T &var )
477  : std::unique_ptr< T, RestoreValue<T> >( &var, { var } )
478  {}
479  explicit ValueRestorer( T &var, const T& newValue )
480  : std::unique_ptr< T, RestoreValue<T> >( &var, { var } )
481  { var = newValue; }
483  : std::unique_ptr < T, RestoreValue<T> > ( std::move(that) ) {};
485  {
486  if (this != &that)
487  std::unique_ptr < T, RestoreValue<T> >::operator=(std::move(that));
488  return *this;
489  }
490 };
491 
492 // inline functions provide convenient parameter type deduction
493 template< typename T >
495 { return ValueRestorer< T >{ var }; }
496 
497 template< typename T >
498 ValueRestorer< T > valueRestorer( T& var, const T& newValue )
499 { return ValueRestorer< T >{ var, newValue }; }
500 
501 /*
502  * A convenience for use with range-for
503  */
504 template <typename Iterator>
505 struct IteratorRange : public std::pair<Iterator, Iterator> {
506  using iterator = Iterator;
507  using reverse_iterator = std::reverse_iterator<Iterator>;
508 
509  IteratorRange (const Iterator &a, const Iterator &b)
510  : std::pair<Iterator, Iterator> ( a, b ) {}
511 
512  IteratorRange (Iterator &&a, Iterator &&b)
513  : std::pair<Iterator, Iterator> ( std::move(a), std::move(b) ) {}
514 
516  { return { this->rbegin(), this->rend() }; }
517 
518  Iterator begin() const { return this->first; }
519  Iterator end() const { return this->second; }
520 
521  reverse_iterator rbegin() const { return reverse_iterator{ this->second }; }
522  reverse_iterator rend() const { return reverse_iterator{ this->first }; }
523 
524  bool empty() const { return this->begin() == this->end(); }
525  explicit operator bool () const { return !this->empty(); }
526  size_t size() const { return std::distance(this->begin(), this->end()); }
527 
528  template <typename T> iterator find(const T &t) const
529  { return std::find(this->begin(), this->end(), t); }
530 
531  template <typename T> long index(const T &t) const
532  {
533  auto iter = this->find(t);
534  if (iter == this->end())
535  return -1;
536  return std::distance(this->begin(), iter);
537  }
538 
539  template <typename T> bool contains(const T &t) const
540  { return this->end() != this->find(t); }
541 
542  template <typename F> iterator find_if(const F &f) const
543  { return std::find_if(this->begin(), this->end(), f); }
544 
545  template <typename F> long index_if(const F &f) const
546  {
547  auto iter = this->find_if(f);
548  if (iter == this->end())
549  return -1;
550  return std::distance(this->begin(), iter);
551  }
552 
553  // to do: use std::all_of, any_of, none_of when available on all platforms
554  template <typename F> bool all_of(const F &f) const
555  {
556  auto notF =
557  [&](typename std::iterator_traits<Iterator>::reference v)
558  { return !f(v); };
559  return !this->any_of( notF );
560  }
561 
562  template <typename F> bool any_of(const F &f) const
563  { return this->end() != this->find_if(f); }
564 
565  template <typename F> bool none_of(const F &f) const
566  { return !this->any_of(f); }
567 
568  template<typename T> struct identity
569  { const T&& operator () (T &&v) const { return std::forward(v); } };
570 
571  // Like std::accumulate, but the iterators implied, and with another
572  // unary operation on the iterator value, pre-composed
573  template<
574  typename R,
575  typename Binary = std::plus< R >,
576  typename Unary = identity< decltype( *std::declval<Iterator>() ) >
577  >
579  R init,
580  Binary binary_op = {},
581  Unary unary_op = {}
582  ) const
583  {
584  R result = init;
585  for (auto&& v : *this)
586  result = binary_op(result, unary_op(v));
587  return result;
588  }
589 
590  // An overload making it more convenient to use with pointers to member
591  // functions
592  template<
593  typename R,
594  typename Binary = std::plus< R >,
595  typename R2, typename C
596  >
598  R init,
599  Binary binary_op,
600  R2 (C :: * pmf) () const
601  ) const
602  {
603  return this->accumulate( init, binary_op, std::mem_fn( pmf ) );
604  }
605 
606  // Some accumulations frequent enough to be worth abbreviation:
607  template<
608  typename Unary = identity< decltype( *std::declval<Iterator>() ) >,
609  typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )
610  >
611  R min( Unary unary_op = {} ) const
612  {
613  return this->accumulate(
614  std::numeric_limits< R >::max(),
615  (const R&(*)(const R&, const R&)) std::min,
616  unary_op
617  );
618  }
619 
620  template<
621  typename R2, typename C,
622  typename R = R2
623  >
624  R min( R2 (C :: * pmf) () const ) const
625  {
626  return this->min( std::mem_fn( pmf ) );
627  }
628 
629  template<
630  typename Unary = identity< decltype( *std::declval<Iterator>() ) >,
631  typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )
632  >
633  R max( Unary unary_op = {} ) const
634  {
635  return this->accumulate(
636  -std::numeric_limits< R >::max(),
637  // std::numeric_limits< R >::lowest(), // TODO C++11
638  (const R&(*)(const R&, const R&)) std::max,
639  unary_op
640  );
641  }
642 
643  template<
644  typename R2, typename C,
645  typename R = R2
646  >
647  R max( R2 (C :: * pmf) () const ) const
648  {
649  return this->max( std::mem_fn( pmf ) );
650  }
651 
652  template<
653  typename Unary = identity< decltype( *std::declval<Iterator>() ) >,
654  typename R = decltype( std::declval<Unary>()( *std::declval<Iterator>() ) )
655  >
656  R sum( Unary unary_op = {} ) const
657  {
658  return this->accumulate(
659  R{ 0 },
660  std::plus< R >{},
661  unary_op
662  );
663  }
664 
665  template<
666  typename R2, typename C,
667  typename R = R2
668  >
669  R sum( R2 (C :: * pmf) () const ) const
670  {
671  return this->sum( std::mem_fn( pmf ) );
672  }
673 };
674 
675 template< typename Iterator>
677 make_iterator_range( const Iterator &i1, const Iterator &i2 )
678 {
679  return { i1, i2 };
680 }
681 
682 template< typename Container >
684 make_iterator_range( Container &container )
685 {
686  return { container.begin(), container.end() };
687 }
688 
689 template< typename Container >
691 make_iterator_range( const Container &container )
692 {
693  return { container.begin(), container.end() };
694 }
695 
696 /*
697  * Transform an iterator sequence, as another iterator sequence
698  */
699 template <
700  typename Result,
701  typename Iterator
702 >
704  : public std::iterator<
705  typename std::iterator_traits<Iterator>::iterator_category,
706  const Result
707  >
708 {
709  // This takes a function on iterators themselves, not on the
710  // dereference of those iterators, in case you ever need the generality.
711  using Function = std::function< Result( const Iterator& ) >;
712 
713 private:
714  Iterator mIterator;
716 
717 public:
718  transform_iterator(const Iterator &iterator, const Function &function)
719  : mIterator( iterator )
720  , mFunction( function )
721  {}
722 
724  { ++this->mIterator; return *this; }
726  { auto copy{*this}; ++this->mIterator; return copy; }
728  { --this->mIterator; return *this; }
730  { auto copy{*this}; --this->mIterator; return copy; }
731 
732  typename transform_iterator::reference operator * ()
733  { return this->mFunction(this->mIterator); }
734 
735  friend inline bool operator == (
736  const transform_iterator &a, const transform_iterator &b)
737  { return a.mIterator == b.mIterator; }
738  friend inline bool operator != (
739  const transform_iterator &a, const transform_iterator &b)
740  { return !(a == b); }
741 };
742 
743 template <
744  typename Iterator,
745  typename Function
746 >
748  decltype( std::declval<Function>() ( std::declval<Iterator>() ) ),
749  Iterator
750 >
751 make_transform_iterator(const Iterator &iterator, Function function)
752 {
753  return { iterator, function };
754 }
755 
756 template < typename Function, typename Iterator > struct value_transformer
757 {
758  // Adapts a function on values to a function on iterators.
759  Function function;
760 
761  auto operator () (const Iterator &iterator)
762  -> decltype( function( *iterator ) ) const
763  { return this->function( *iterator ); }
764 };
765 
766 template <
767  typename Function,
768  typename Iterator
769 >
771  decltype( std::declval<Function>()( *std::declval<Iterator>() ) ),
772  Iterator
773 >;
774 
775 template <
776  typename Function,
777  typename Iterator
778 >
780 make_value_transform_iterator(const Iterator &iterator, Function function)
781 {
782  using NewFunction = value_transformer<Function, Iterator>;
783  return { iterator, NewFunction{ function } };
784 }
785 
786 #if !wxCHECK_VERSION(3, 1, 0)
787 // For using std::unordered_map on wxString
788 namespace std
789 {
790  template<typename T> struct hash;
791  template<> struct hash< wxString > {
792  size_t operator () (const wxString &str) const // noexcept
793  {
794  auto stdstr = str.ToStdWstring(); // no allocations, a cheap fetch
795  using Hasher = hash< decltype(stdstr) >;
796  return Hasher{}( stdstr );
797  }
798  };
799 }
800 #endif
801 
802 #endif // __AUDACITY_MEMORY_X_H__
Maybe & operator=(const Maybe &that)
Definition: MemoryX.h:217
void operator()(T *p) const
Definition: MemoryX.h:467
R min(R2(C::*pmf)() const ) const
Definition: MemoryX.h:624
std::function< Result(const Iterator &) > Function
Definition: MemoryX.h:711
memory.h template class for making an array of arrays.
Definition: MemoryX.h:137
bool contains(const T &t) const
Definition: MemoryX.h:539
reverse_iterator rend() const
Definition: MemoryX.h:522
iterator find(const T &t) const
Definition: MemoryX.h:528
std::unique_ptr< T > movable_ptr
Definition: MemoryX.h:332
reverse_iterator rbegin() const
Definition: MemoryX.h:521
const T && operator()(T &&v) const
Definition: MemoryX.h:569
IteratorRange(Iterator &&a, Iterator &&b)
Definition: MemoryX.h:512
bool none_of(const F &f) const
Definition: MemoryX.h:565
std::unique_ptr< T, Deleter > movable_ptr_with_deleter_base
Definition: MemoryX.h:333
char storage[sizeof(X)]
Definition: MemoryX.h:310
value_transform_iterator< Function, Iterator > make_value_transform_iterator(const Iterator &iterator, Function function)
Definition: MemoryX.h:780
void reinit(Integral count, bool initialize=false)
Definition: MemoryX.h:117
X * address()
Definition: MemoryX.h:296
R min(Unary unary_op={}) const
Definition: MemoryX.h:611
ArraysOf(Integral1 N, Integral2 M, bool initialize=false)
Definition: MemoryX.h:148
Iterator mIterator
Definition: MemoryX.h:714
Final_action(F f)
Definition: MemoryX.h:445
void reinit(Integral count, bool initialize)
Definition: MemoryX.h:172
~Maybe()
Definition: MemoryX.h:260
movable_ptr_with_deleter(T *p, const Deleter &d)
Definition: MemoryX.h:355
Definition: MemoryX.h:204
ArrayOf & operator=(ArrayOf &&that)
Definition: MemoryX.h:105
R accumulate(R init, Binary binary_op={}, Unary unary_op={}) const
Definition: MemoryX.h:578
friend bool operator==(const transform_iterator &a, const transform_iterator &b)
Definition: MemoryX.h:735
void reset()
Definition: MemoryX.h:283
IteratorRange< reverse_iterator > reversal() const
Definition: MemoryX.h:515
bool any_of(const F &f) const
Definition: MemoryX.h:562
iterator find_if(const F &f) const
Definition: MemoryX.h:542
movable_ptr< T > make_movable(Args &&...args)
Definition: MemoryX.h:337
std::unique_ptr< Character[], freer > MallocString
Definition: MemoryX.h:417
~Final_action()
Definition: MemoryX.h:446
R accumulate(R init, Binary binary_op, R2(C::*pmf)() const ) const
Definition: MemoryX.h:597
Iterator begin() const
Definition: MemoryX.h:518
ArrayOf(Integral count, bool initialize=false)
Definition: MemoryX.h:92
IteratorRange(const Iterator &a, const Iterator &b)
Definition: MemoryX.h:509
movable_ptr_with_deleter< T, Deleter > make_movable_with_deleter(const Deleter &d, Args &&...args)
Definition: MemoryX.h:397
unique_ptr< X > scalar_case
Definition: MemoryX.h:44
transform_iterator(const Iterator &iterator, const Function &function)
Definition: MemoryX.h:718
ValueRestorer & operator=(ValueRestorer &&that)
Definition: MemoryX.h:484
IteratorRange< Iterator > make_iterator_range(const Iterator &i1, const Iterator &i2)
Definition: MemoryX.h:677
bool empty() const
Definition: MemoryX.h:524
Maybe(const Maybe &that)
Definition: MemoryX.h:211
R sum(R2(C::*pmf)() const ) const
Definition: MemoryX.h:669
int min(int a, int b)
X * operator->() const
Definition: MemoryX.h:273
double d
Definition: MemoryX.h:309
ArrayOf(ArrayOf &&that)
Definition: MemoryX.h:100
transform_iterator< decltype(std::declval< Function >)(std::declval< Iterator >))), Iterator > make_transform_iterator(const Iterator &iterator, Function function)
Definition: MemoryX.h:751
movable_ptr_with_deleter(movable_ptr_with_deleter &&that)
Definition: MemoryX.h:378
Function mFunction
Definition: MemoryX.h:715
R sum(Unary unary_op={}) const
Definition: MemoryX.h:656
movable_ptr_with_deleter & operator=(movable_ptr_with_deleter &&that)
Definition: MemoryX.h:383
ArraysOf & operator=(ArraysOf &&that)
Definition: MemoryX.h:159
ArraysOf(Integral N)
Definition: MemoryX.h:143
X & operator*() const
Definition: MemoryX.h:268
ValueRestorer< T > valueRestorer(T &var)
Definition: MemoryX.h:494
R max(R2(C::*pmf)() const ) const
Definition: MemoryX.h:647
Definition: MemoryX.h:405
void reinit(Integral count)
Definition: MemoryX.h:166
friend bool operator!=(const transform_iterator &a, const transform_iterator &b)
Definition: MemoryX.h:738
Memory.h template class for making an array of float, bool, etc.
Definition: MemoryX.h:86
long index(const T &t) const
Definition: MemoryX.h:531
Maybe()
Definition: MemoryX.h:208
transform_iterator & operator--()
Definition: MemoryX.h:727
transform_iterator & operator++()
Definition: MemoryX.h:723
long index_if(const F &f) const
Definition: MemoryX.h:545
transform_iterator::reference operator*()
Definition: MemoryX.h:732
X * get() const
Definition: MemoryX.h:278
std::reverse_iterator< Iterator > reverse_iterator
Definition: MemoryX.h:507
std::unique_ptr< T, Destroyer< T >> Destroy_ptr
Definition: MemoryX.h:433
void operator()(void *p) const
Definition: MemoryX.h:405
ValueRestorer(T &var)
Definition: MemoryX.h:476
Iterator iterator
Definition: MemoryX.h:506
ArraysOf()
Definition: MemoryX.h:140
X * pp
Definition: MemoryX.h:313
bool all_of(const F &f) const
Definition: MemoryX.h:554
unique_ptr< X[]> array_case
Definition: MemoryX.h:49
std::unique_ptr< T, freer > MallocPtr
Definition: MemoryX.h:411
size_t size() const
Definition: MemoryX.h:526
void reinit(Integral1 countN, Integral2 countM, bool initialize=false)
Definition: MemoryX.h:178
R max(Unary unary_op={}) const
Definition: MemoryX.h:633
void create(Args &&...args)
Definition: MemoryX.h:251
#define safenew
Definition: MemoryX.h:8
void operator()(T *p) const
Definition: MemoryX.h:426
auto operator()(const Iterator &iterator) -> decltype(function(*iterator)) const
Definition: MemoryX.h:761
Iterator end() const
Definition: MemoryX.h:519
Maybe(Maybe &&that)
Definition: MemoryX.h:228
ArrayOf()
Definition: MemoryX.h:89