#ifndef ITER_FILTER_FALSE_HPP_ #define ITER_FILTER_FALSE_HPP_ #include "internal/iterbase.hpp" #include "filter.hpp" #include namespace iter { namespace detail { // Callable object that reverses the boolean result of another // callable, taking the object in a Container's iterator template class PredicateFlipper { private: FilterFunc filter_func; public: PredicateFlipper(FilterFunc in_filter_func) : filter_func(in_filter_func) {} PredicateFlipper() = delete; PredicateFlipper(const PredicateFlipper&) = default; // Calls the filter_func bool operator()(const iter::impl::iterator_deref item) const { return !bool(filter_func(item)); } // with non-const incase FilterFunc::operator() is non-const bool operator()(const iter::impl::iterator_deref item) { return !bool(filter_func(item)); } }; // Reverses the bool() conversion result of anything that supports a // bool conversion template class BoolFlipper { public: bool operator()(const iter::impl::iterator_deref item) const { return !bool(item); } }; } // Creates a PredicateFlipper for the predicate function, which reverses // the bool result of the function. The PredicateFlipper is then passed // to the normal filter() function template auto filterfalse(FilterFunc filter_func, Container&& container) { return filter(detail::PredicateFlipper(filter_func), std::forward(container)); } // Single argument version, uses a BoolFlipper to reverse the truthiness // of an object template auto filterfalse(Container&& container) { return filter( detail::BoolFlipper(), std::forward(container)); } // specializations for initializer_lists template auto filterfalse(FilterFunc filter_func, std::initializer_list container) { return filter( detail::PredicateFlipper>( filter_func), std::move(container)); } // Single argument version, uses a BoolFlipper to reverse the truthiness // of an object template auto filterfalse(std::initializer_list container) { return filter( detail::BoolFlipper>(), std::move(container)); } } #endif