souffle
2.0.2-371-g6315b36
|
Go to the documentation of this file.
25 #include <type_traits>
36 using Own = std::unique_ptr<A>;
39 using VecOwn = std::vector<Own<A>>;
41 template <
typename A,
typename B = A,
typename... Args>
43 return Own<A>(
new B(std::forward<Args>(xs)...));
69 bool contains(
const C& container,
const typename C::value_type& element) {
70 return std::find(container.begin(), container.end(), element) != container.end();
75 bool contains(
const std::set<A>& container,
const A& element) {
76 return container.find(element) != container.end();
86 bool contains(
const C& container,
const typename C::value_type::first_type& element) {
87 return container.find(element) != container.end();
95 typename C::value_type
getIf(
const C& container, std::function<
bool(
const typename C::value_type)> pred) {
96 auto res = std::find_if(container.begin(), container.end(),
97 [&](
const typename C::value_type item) { return pred(item); });
98 return res == container.end() ? nullptr : *res;
104 template <
typename C>
105 typename C::mapped_type
const&
getOr(
106 const C& container,
typename C::key_type key,
const typename C::mapped_type& defaultValue) {
107 auto it = container.find(key);
109 if (it != container.end()) {
121 template <
typename T>
123 return std::vector<T>();
131 template <
typename T,
typename... R>
132 std::vector<T>
toVector(
const T& first,
const R&... rest) {
133 return {first, rest...};
139 template <
typename T>
140 std::vector<T*>
toPtrVector(
const std::vector<std::unique_ptr<T>>& v) {
143 res.push_back(
e.get());
151 template <
typename A,
typename F >
152 auto map(
const std::vector<A>& xs, F&& f) {
153 std::vector<decltype(f(xs[0]))> ys;
154 ys.reserve(xs.size());
155 for (
auto&& x : xs) {
156 ys.emplace_back(f(x));
165 template <
typename A>
166 auto clone(
const std::vector<A*>& xs) {
167 std::vector<std::unique_ptr<A>> ys;
168 ys.reserve(xs.size());
169 for (
auto&& x : xs) {
170 ys.emplace_back(x ? std::unique_ptr<A>(x->clone()) :
nullptr);
175 template <
typename A>
176 auto clone(
const std::vector<std::unique_ptr<A>>& xs) {
177 std::vector<std::unique_ptr<A>> ys;
178 ys.reserve(xs.size());
179 for (
auto&& x : xs) {
180 ys.emplace_back(x ? std::unique_ptr<A>(x->clone()) :
nullptr);
197 struct IterDerefWrapper :
public std::iterator<std::forward_iterator_tag, T> {
216 return iter == other.iter;
245 template <
typename Iter>
253 template <
typename T>
278 return !(*
this == other);
306 template <
typename Iter>
312 range(Iter
a, Iter
b) :
a(std::move(
a)),
b(std::move(
b)) {}
323 const Iter&
begin()
const {
331 const Iter&
end()
const {
341 std::vector<range>
partition(
int np = 100) {
344 for (
auto i =
a;
i !=
b; ++
i) {
351 std::vector<range> res;
360 if (
i >= (s + (
p < r ? 1 : 0))) {
361 res.push_back({last, cur});
368 res.push_back({last, cur});
382 template <
typename Iter>
383 range<Iter>
make_range(
const Iter& a,
const Iter&
b) {
384 return range<Iter>(a,
b);
397 template <
typename toType,
typename baseType>
398 bool castEq(
const baseType* left,
const baseType* right) {
399 if (
auto castedLeft =
dynamic_cast<const toType*
>(left)) {
400 if (
auto castedRight =
dynamic_cast<const toType*
>(right)) {
401 return castedLeft == castedRight;
410 template <
typename T>
426 template <
typename Container,
typename Comparator>
434 if (a.size() !=
b.size()) {
439 return std::equal(a.begin(), a.end(),
b.begin(), comp);
446 template <
typename T,
template <
typename...>
class Container>
447 bool equal_targets(
const Container<T*>& a,
const Container<T*>&
b) {
455 template <
typename T,
template <
typename...>
class Container>
456 bool equal_targets(
const Container<std::unique_ptr<T>>& a,
const Container<std::unique_ptr<T>>&
b) {
464 template <
typename Key,
typename Value>
466 const std::map<Key, std::unique_ptr<Value>>& a,
const std::map<Key, std::unique_ptr<Value>>&
b) {
469 a,
b, [&comp](
auto& a,
auto&
b) {
return a.first ==
b.first && comp(a.second,
b.second); });
A utility class enabling representation of ranges by pairing two iterator instances marking lower and...
IterDerefWrapper & operator=(const IterDerefWrapper &)=default
bool operator()(const T &a, const T &b) const
range & operator=(const range &)=default
bool contains(const C &container, const typename C::value_type &element)
A utility to check generically whether a given element is contained in a given container.
SingleValueIterator & operator++()
l j a showGridBackground &&c b raw series this eventEmitter e
bool operator==(const IterDerefWrapper &other) const
auto map(const std::vector< A > &xs, F &&f)
Applies a function to each element of a vector and returns the results.
IterDerefWrapper()=default
const T & operator*() const
bool castEq(const baseType *left, const baseType *right)
Cast the values, from baseType to toType and compare using ==.
An iterator to be utilized if there is only a single element to iterate over.
IterDerefWrapper< Iter > derefIter(const Iter &iter)
A factory function enabling the construction of a dereferencing iterator utilizing the automated dedu...
bool operator!=(const IterDerefWrapper &other) const
C::mapped_type const & getOr(const C &container, typename C::key_type key, const typename C::mapped_type &defaultValue)
Get value for a given key; if not found, return default value.
auto clone(const std::vector< A * > &xs)
Own< A > mk(Args &&... xs)
Use to range-for iterate in reverse.
SingleValueIterator()=default
range< Iter > make_range(const Iter &a, const Iter &b)
A utility function enabling the construction of ranges without explicitly specifying the iterator typ...
bool equal_targets(const Container &a, const Container &b, const Comparator &comp)
A function testing whether two containers are equal with the given Comparator.
const T * operator->() const
A wrapper for an iterator obtaining pointers of a certain type, dereferencing values before forwardin...
SingleValueIterator & operator=(const SingleValueIterator &other)=default
std::vector< T > toVector()
A utility function enabling the creation of a vector with a fixed set of elements within a single exp...
std::vector< range > partition(int np=100)
const T & operator*() const
C::value_type getIf(const C &container, std::function< bool(const typename C::value_type)> pred)
Returns the first element in a container that satisfies a given predicate, nullptr otherwise.
l j a showGridBackground &&c b raw series this eventEmitter b
const T * operator->() const
bool operator!=(const SingleValueIterator &other) const
IterDerefWrapper & operator++()
A functor class supporting the values pointers are pointing to.
bool operator==(const SingleValueIterator &other) const
std::vector< T * > toPtrVector(const std::vector< std::unique_ptr< T >> &v)
A utility function enabling the creation of a vector of pointers.
std::vector< Own< A > > VecOwn
a horizontalBars(j=m=void 0===a.axisX.type?new c.AutoScaleAxis(c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})):a.axisX.type.call(c, c.Axis.units.x, b.normalized.series, o, c.extend({}, a.axisX,{highLow:d, referenceValue:0})), l=n=void 0===a.axisY.type?new c.StepAxis(c.Axis.units.y, b.normalized.series, o,{ticks:k}):a.axisY.type.call(c, c.Axis.units.y, b.normalized.series, o, a.axisY)) var p