@@ -52,6 +52,21 @@ template <class T, class U> std::vector<T>& operator+=(std::vector<T>& _a, U&& _
52
52
std::move (_b.begin (), _b.end (), std::back_inserter (_a));
53
53
return _a;
54
54
}
55
+
56
+ // / Concatenate the contents of a container onto a list
57
+ template <class T , class U > std::list<T>& operator +=(std::list<T>& _a, U& _b)
58
+ {
59
+ for (auto const & i: _b)
60
+ _a.push_back (T (i));
61
+ return _a;
62
+ }
63
+ // / Concatenate the contents of a container onto a list, move variant.
64
+ template <class T , class U > std::list<T>& operator +=(std::list<T>& _a, U&& _b)
65
+ {
66
+ std::move (_b.begin (), _b.end (), std::back_inserter (_a));
67
+ return _a;
68
+ }
69
+
55
70
// / Concatenate the contents of a container onto a multiset
56
71
template <class U , class ... T> std::multiset<T...>& operator +=(std::multiset<T...>& _a, U& _b)
57
72
{
@@ -321,6 +336,44 @@ void joinMap(std::map<K, V>& _a, std::map<K, V>&& _b, F _conflictSolver)
321
336
}
322
337
}
323
338
339
+ namespace detail
340
+ {
341
+
342
+ template <typename Container, typename Value>
343
+ auto findOffset (Container&& _container, Value&& _value, int )
344
+ -> decltype(_container.find(_value) == _container.end(), std::distance(_container.begin(), _container.find(_value)), std::optional<size_t>())
345
+ {
346
+ auto it = _container.find (std::forward<Value>(_value));
347
+ auto end = _container.end ();
348
+ if (it == end)
349
+ return std::nullopt;
350
+ return std::distance (_container.begin (), it);
351
+ }
352
+ template <typename Range, typename Value>
353
+ auto findOffset (Range&& _range, Value&& _value, void *)
354
+ -> decltype(std::find(std::begin(_range), std::end(_range), std::forward<Value>(_value)) == std::end(_range), std::optional<size_t>())
355
+ {
356
+ auto begin = std::begin (_range);
357
+ auto end = std::end (_range);
358
+ auto it = std::find (begin, end, std::forward<Value>(_value));
359
+ if (it == end)
360
+ return std::nullopt;
361
+ return std::distance (begin, it);
362
+ }
363
+
364
+ }
365
+
366
+ // / @returns an std::optional<size_t> containing the offset of the first element in @a _range that is equal to @a _value,
367
+ // / if any, or std::nullopt otherwise.
368
+ // / Uses a linear search (``std::find``) unless @a _range is a container and provides a
369
+ // / suitable ``.find`` function (e.g. it will use the logarithmic ``.find`` function in ``std::set`` instead).
370
+ template <typename Range>
371
+ auto findOffset (Range&& _range, std::remove_reference_t <decltype (*std::cbegin (_range))> const & _value)
372
+ -> decltype(detail::findOffset(std::forward<Range>(_range), _value, 0))
373
+ {
374
+ return detail::findOffset (std::forward<Range>(_range), _value, 0 );
375
+ }
376
+
324
377
// String conversion functions, mainly to/from hex/nibble/byte representations.
325
378
326
379
enum class WhenError
0 commit comments