Krita Source Code Documentation
Loading...
Searching...
No Matches
kismpl Namespace Reference

Namespaces

namespace  detail
 

Classes

struct  finally
 
struct  first_type
 
struct  overloaded
 

Typedefs

template<typename... T>
using first_type_t = typename first_type<T...>::type
 
template<std::size_t Num>
using make_index_sequence_from_1
 

Functions

template<typename F , typename Tuple >
auto apply_to_tuple (F f, Tuple &&t)
 
template<typename Fun , typename... Args, typename T = typename first_type_t<std::remove_reference_t<Args>...>::value_type>
std::optional< T > fold_optional (Fun &&fun, Args &&...args)
 
std::future< voidmake_ready_future ()
 
template<typename T >
std::future< std::decay_t< T > > make_ready_future (T &&value)
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_equal_to (MemTypeNoRef Class::*ptr, MemType &&value)
 mem_equal_to is an unary functor that compares a member of the object to a given value
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_equal_to (MemTypeNoRef(Class::*ptr)() noexcept, MemType &&value)
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_equal_to (MemTypeNoRef(Class::*ptr)(), MemType &&value)
 
template<typename Class , typename MemType >
auto mem_greater (MemType Class::*ptr)
 mem_greater is a binary functor that compares a member of the object to a given value or two objects based on the value of their members
 
template<typename Class , typename MemType >
auto mem_greater (MemType(Class::*ptr)() noexcept)
 
template<typename Class , typename MemType >
auto mem_greater (MemType(Class::*ptr)())
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_greater (MemTypeNoRef Class::*ptr, MemType &&value)
 mem_greater is an unary functor that compares a member of the object to a given value
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_greater (MemTypeNoRef(Class::*ptr)() noexcept, MemType &&value)
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_greater (MemTypeNoRef(Class::*ptr)(), MemType &&value)
 
template<typename Class , typename MemType >
auto mem_greater_equal (MemType Class::*ptr)
 mem_greater_equal is a binary functor that compares a member of the object to a given value or two objects based on the value of their members
 
template<typename Class , typename MemType >
auto mem_greater_equal (MemType(Class::*ptr)() noexcept)
 
template<typename Class , typename MemType >
auto mem_greater_equal (MemType(Class::*ptr)())
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_greater_equal (MemTypeNoRef Class::*ptr, MemType &&value)
 mem_greater_equal is an unary functor that compares a member of the object to a given value
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_greater_equal (MemTypeNoRef(Class::*ptr)() noexcept, MemType &&value)
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_greater_equal (MemTypeNoRef(Class::*ptr)(), MemType &&value)
 
template<typename Class , typename MemType >
auto mem_less (MemType Class::*ptr)
 mem_less is a binary functor that compares a member of the object to a given value or two objects based on the value of their members
 
template<typename Class , typename MemType >
auto mem_less (MemType(Class::*ptr)() noexcept)
 
template<typename Class , typename MemType >
auto mem_less (MemType(Class::*ptr)())
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_less (MemTypeNoRef Class::*ptr, MemType &&value)
 mem_less is an unary functor that compares a member of the object to a given value
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_less (MemTypeNoRef(Class::*ptr)() noexcept, MemType &&value)
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_less (MemTypeNoRef(Class::*ptr)(), MemType &&value)
 
template<typename Class , typename MemType >
auto mem_less_equal (MemType Class::*ptr)
 mem_less_equal is a binary functor that compares a member of the object to a given value or two objects based on the value of their members
 
template<typename Class , typename MemType >
auto mem_less_equal (MemType(Class::*ptr)() noexcept)
 
template<typename Class , typename MemType >
auto mem_less_equal (MemType(Class::*ptr)())
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_less_equal (MemTypeNoRef Class::*ptr, MemType &&value)
 mem_less_equal is an unary functor that compares a member of the object to a given value
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_less_equal (MemTypeNoRef(Class::*ptr)() noexcept, MemType &&value)
 
template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto mem_less_equal (MemTypeNoRef(Class::*ptr)(), MemType &&value)
 
template<class... Ts>
 overloaded (Ts...) -> overloaded< Ts... >
 
template<class T , class Function >
auto then (std::future< T > &&future, Function &&func) -> std::future< decltype(func(std::move(future)))>
 

Variables

constexpr auto unzip_wrapper
 

Detailed Description

'kismpl' stands for kis-meta-program-library

Typedef Documentation

◆ first_type_t

template<typename... T>
using kismpl::first_type_t = typename first_type<T...>::type

A helper function to return the first type of a parameter pack

Definition at line 101 of file KisMpl.h.

◆ make_index_sequence_from_1

template<std::size_t Num>
using kismpl::make_index_sequence_from_1
Initial value:
typename detail::make_index_sequence_from_1_impl<Num>::type

Creates an index sequence in range 1, 2, 3, ..., Num

Same as std::make_index_sequence, but starts counting from 1 instead of 0.

Definition at line 44 of file KisMpl.h.

Function Documentation

◆ apply_to_tuple()

template<typename F , typename Tuple >
auto kismpl::apply_to_tuple ( F f,
Tuple && t )

Apply a given functor F to each element of the tuple and return a tuple consisting of the resulting values.

Definition at line 60 of file KisMpl.h.

60 {
61 return detail::apply_to_tuple_impl(std::forward<F>(f), std::forward<Tuple>(t),
62 std::make_index_sequence<std::tuple_size<std::remove_reference_t<Tuple>>::value>{});
63}
float value(const T *src, size_t ch)

References kismpl::detail::apply_to_tuple_impl(), and value().

◆ fold_optional()

template<typename Fun , typename... Args, typename T = typename first_type_t<std::remove_reference_t<Args>...>::value_type>
std::optional< T > kismpl::fold_optional ( Fun && fun,
Args &&... args )

Folds all the valid optional values using the binary function fun into one optional value. When none optional values are present, an empty optional of the specified type is returned.

Definition at line 137 of file KisMpl.h.

137 {
138 return detail::fold_optional_impl<Fun, T>{std::forward<Fun>(fun)}.fold(args...);
139}
std::optional< T > fold(const std::optional< T > &first)
Definition KisMpl.h:106

References kismpl::detail::fold_optional_impl< Fun, T >::fold().

◆ make_ready_future() [1/2]

std::future< void > kismpl::make_ready_future ( )

Definition at line 24 of file KisFutureUtils.h.

24 {
25 std::promise<void> promise;
26 promise.set_value();
27 return promise.get_future();
28}

◆ make_ready_future() [2/2]

template<typename T >
std::future< std::decay_t< T > > kismpl::make_ready_future ( T && value)

Create a future whose value has already been evaluated

See rejected C++ proposal for details: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3721.pdf

Definition at line 18 of file KisFutureUtils.h.

18 {
19 std::promise<T> promise;
20 promise.set_value(std::forward<T>(value));
21 return promise.get_future();
22}

References value().

◆ mem_equal_to() [1/3]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_equal_to ( MemTypeNoRef Class::* ptr,
MemType && value )
inline

mem_equal_to is an unary functor that compares a member of the object to a given value

The functor is supposed to be used in std::find_if and other standard algorithms. It can automatically dereference a pointer-to-member or a pointer-to-method.

  • Usage:
    \code{.cpp}
    
    struct Struct {
        Struct (int _id) : id(_id) {}
    
        int id = -1;
        int idConstFunc() const {
            return id;
        }
    };
    
    std::vector<Struct> vec({{0},{1},{2},{3}});
    
    // find an element, which has member 'id' set to 1
    auto it1 = std::find_if(vec.begin(), vec.end(), kismpl::mem_equal_to(&Struct::id, 1));
    
    // find an element, whose member function 'idConstFunc()' returns 1
    auto it2 = std::find_if(vec.begin(), vec.end(), kismpl::mem_equal_to(&Struct::idConstFunc, 1));
    
    // the functor can automatically dereference pointers and shared pointers
    std::vector<std::shared_ptr<Struct>> vec({std::make_shared<Struct>(0),
                                              std::make_shared<Struct>(1),
                                              std::make_shared<Struct>(2),
                                              std::make_shared<Struct>(3),
                                              std::make_shared<Struct>(4)});
    
    // the shared pointer is automatically lifted by the functor
    auto it3 = std::find_if(vec.begin(), vec.end(), kismpl::mem_equal_to(&Struct::id, 1));
    
    \endcode
    

Definition at line 233 of file KisMpl.h.

233 {
234 return detail::mem_checker<std::equal_to<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
235}

References value().

◆ mem_equal_to() [2/3]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_equal_to ( MemTypeNoRef(Class::*)() noexcept ptr,
MemType && value )
inline

Definition at line 251 of file KisMpl.h.

251 {
252 return detail::mem_checker<std::equal_to<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
253}

References value().

◆ mem_equal_to() [3/3]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_equal_to ( MemTypeNoRef(Class::*)() ptr,
MemType && value )
inline

Definition at line 239 of file KisMpl.h.

239 {
240 return detail::mem_checker<std::equal_to<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
241}

References value().

◆ mem_greater() [1/6]

template<typename Class , typename MemType >
auto kismpl::mem_greater ( MemType Class::* ptr)
inline

mem_greater is a binary functor that compares a member of the object to a given value or two objects based on the value of their members

See also
mem_less

Definition at line 519 of file KisMpl.h.

519 {
520 return detail::mem_compare<std::greater<>, Class, MemType, decltype(ptr)>{ptr};
521}

◆ mem_greater() [2/6]

template<typename Class , typename MemType >
auto kismpl::mem_greater ( MemType(Class::*)() noexcept ptr)
inline

Definition at line 537 of file KisMpl.h.

537 {
538 return detail::mem_compare<std::greater<>, Class, MemType, decltype(ptr)>{ptr};
539}

◆ mem_greater() [3/6]

template<typename Class , typename MemType >
auto kismpl::mem_greater ( MemType(Class::*)() ptr)
inline

Definition at line 525 of file KisMpl.h.

525 {
526 return detail::mem_compare<std::greater<>, Class, MemType, decltype(ptr)>{ptr};
527}

◆ mem_greater() [4/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_greater ( MemTypeNoRef Class::* ptr,
MemType && value )
inline

mem_greater is an unary functor that compares a member of the object to a given value

See also
mem_equal_to

Definition at line 341 of file KisMpl.h.

341 {
342 return detail::mem_checker<std::greater<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
343}

References value().

◆ mem_greater() [5/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_greater ( MemTypeNoRef(Class::*)() noexcept ptr,
MemType && value )
inline

Definition at line 359 of file KisMpl.h.

359 {
360 return detail::mem_checker<std::greater<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
361}

References value().

◆ mem_greater() [6/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_greater ( MemTypeNoRef(Class::*)() ptr,
MemType && value )
inline

Definition at line 347 of file KisMpl.h.

347 {
348 return detail::mem_checker<std::greater<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
349}

References value().

◆ mem_greater_equal() [1/6]

template<typename Class , typename MemType >
auto kismpl::mem_greater_equal ( MemType Class::* ptr)
inline

mem_greater_equal is a binary functor that compares a member of the object to a given value or two objects based on the value of their members

See also
mem_less

Definition at line 555 of file KisMpl.h.

555 {
556 return detail::mem_compare<std::greater_equal<>, Class, MemType, decltype(ptr)>{ptr};
557}

◆ mem_greater_equal() [2/6]

template<typename Class , typename MemType >
auto kismpl::mem_greater_equal ( MemType(Class::*)() noexcept ptr)
inline

Definition at line 573 of file KisMpl.h.

573 {
574 return detail::mem_compare<std::greater_equal<>, Class, MemType, decltype(ptr)>{ptr};
575}

◆ mem_greater_equal() [3/6]

template<typename Class , typename MemType >
auto kismpl::mem_greater_equal ( MemType(Class::*)() ptr)
inline

Definition at line 561 of file KisMpl.h.

561 {
562 return detail::mem_compare<std::greater_equal<>, Class, MemType, decltype(ptr)>{ptr};
563}

◆ mem_greater_equal() [4/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_greater_equal ( MemTypeNoRef Class::* ptr,
MemType && value )
inline

mem_greater_equal is an unary functor that compares a member of the object to a given value

See also
mem_equal_to

Definition at line 378 of file KisMpl.h.

378 {
379 return detail::mem_checker<std::greater_equal<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
380}

References value().

◆ mem_greater_equal() [5/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_greater_equal ( MemTypeNoRef(Class::*)() noexcept ptr,
MemType && value )
inline

Definition at line 396 of file KisMpl.h.

396 {
397 return detail::mem_checker<std::greater_equal<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
398}

References value().

◆ mem_greater_equal() [6/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_greater_equal ( MemTypeNoRef(Class::*)() ptr,
MemType && value )
inline

Definition at line 384 of file KisMpl.h.

384 {
385 return detail::mem_checker<std::greater_equal<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
386}

References value().

◆ mem_less() [1/6]

template<typename Class , typename MemType >
auto kismpl::mem_less ( MemType Class::* ptr)
inline

mem_less is a binary functor that compares a member of the object to a given value or two objects based on the value of their members

The functor is supposed to be used in std::lower_bound and other standard algorithms. It can automatically dereference a pointer-to-member or a pointer-to-method.

  • Usage:
    \code{.cpp}
    
    struct Struct {
        Struct (int _id) : id(_id) {}
    
        int id = -1;
        int idConstFunc() const {
            return id;
        }
    };
    
    std::vector<Struct> vec({{0},{1},{2},{3}});
    
    // find the first element, whose 'id' is not less than 1
    auto it1 = std::lower_bound(vec.begin(), vec.end(), 1, kismpl::mem_less(&Struct::id));
    
    // find the first element, whose 'id' returned by 'idConstFunc()' is not less than 1
    auto it2 = std::lower_bound(vec.begin(), vec.end(), 1, kismpl::mem_less(&Struct::idConstFunc, 1));
    
    // the functor can automatically dereference pointers and shared pointers
    std::vector<std::shared_ptr<Struct>> vec({std::make_shared<Struct>(0),
                                              std::make_shared<Struct>(1),
                                              std::make_shared<Struct>(2),
                                              std::make_shared<Struct>(3),
                                              std::make_shared<Struct>(4)});
    
    // the shared pointer is automatically lifted by the functor
    auto it3 = std::lower_bound(vec.begin(), vec.end(), 1, kismpl::mem_less(&Struct::id));
    
    \endcode
    

Definition at line 448 of file KisMpl.h.

448 {
449 return detail::mem_compare<std::less<>, Class, MemType, decltype(ptr)>{ptr};
450}

◆ mem_less() [2/6]

template<typename Class , typename MemType >
auto kismpl::mem_less ( MemType(Class::*)() noexcept ptr)
inline

Definition at line 466 of file KisMpl.h.

466 {
467 return detail::mem_compare<std::less<>, Class, MemType, decltype(ptr)>{ptr};
468}

◆ mem_less() [3/6]

template<typename Class , typename MemType >
auto kismpl::mem_less ( MemType(Class::*)() ptr)
inline

Definition at line 454 of file KisMpl.h.

454 {
455 return detail::mem_compare<std::less<>, Class, MemType, decltype(ptr)>{ptr};
456}

◆ mem_less() [4/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_less ( MemTypeNoRef Class::* ptr,
MemType && value )
inline

mem_less is an unary functor that compares a member of the object to a given value

See also
mem_equal_to

Definition at line 269 of file KisMpl.h.

269 {
270 return detail::mem_checker<std::less<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
271}

References value().

◆ mem_less() [5/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_less ( MemTypeNoRef(Class::*)() noexcept ptr,
MemType && value )
inline

Definition at line 287 of file KisMpl.h.

287 {
288 return detail::mem_checker<std::less<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
289}

References value().

◆ mem_less() [6/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_less ( MemTypeNoRef(Class::*)() ptr,
MemType && value )
inline

Definition at line 275 of file KisMpl.h.

275 {
276 return detail::mem_checker<std::less<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
277}

References value().

◆ mem_less_equal() [1/6]

template<typename Class , typename MemType >
auto kismpl::mem_less_equal ( MemType Class::* ptr)
inline

mem_less_equal is a binary functor that compares a member of the object to a given value or two objects based on the value of their members

See also
mem_less

Definition at line 483 of file KisMpl.h.

483 {
484 return detail::mem_compare<std::less_equal<>, Class, MemType, decltype(ptr)>{ptr};
485}

◆ mem_less_equal() [2/6]

template<typename Class , typename MemType >
auto kismpl::mem_less_equal ( MemType(Class::*)() noexcept ptr)
inline

Definition at line 501 of file KisMpl.h.

501 {
502 return detail::mem_compare<std::less_equal<>, Class, MemType, decltype(ptr)>{ptr};
503}

◆ mem_less_equal() [3/6]

template<typename Class , typename MemType >
auto kismpl::mem_less_equal ( MemType(Class::*)() ptr)
inline

Definition at line 489 of file KisMpl.h.

489 {
490 return detail::mem_compare<std::less_equal<>, Class, MemType, decltype(ptr)>{ptr};
491}

◆ mem_less_equal() [4/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_less_equal ( MemTypeNoRef Class::* ptr,
MemType && value )
inline

mem_less_equal is an unary functor that compares a member of the object to a given value

See also
mem_equal_to

Definition at line 305 of file KisMpl.h.

305 {
306 return detail::mem_checker<std::less_equal<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
307}

References value().

◆ mem_less_equal() [5/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_less_equal ( MemTypeNoRef(Class::*)() noexcept ptr,
MemType && value )
inline

Definition at line 323 of file KisMpl.h.

323 {
324 return detail::mem_checker<std::less_equal<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
325}

References value().

◆ mem_less_equal() [6/6]

template<typename Class , typename MemType , typename MemTypeNoRef = std::remove_reference_t<MemType>>
auto kismpl::mem_less_equal ( MemTypeNoRef(Class::*)() ptr,
MemType && value )
inline

Definition at line 311 of file KisMpl.h.

311 {
312 return detail::mem_checker<std::less_equal<>, Class, MemTypeNoRef, decltype(ptr)>{ptr, std::forward<MemType>(value)};
313}

References value().

◆ overloaded()

template<class... Ts>
kismpl::overloaded ( Ts... ) -> overloaded< Ts... >

◆ then()

template<class T , class Function >
auto kismpl::then ( std::future< T > && future,
Function && func ) -> std::future<decltype(func(std::move(future)))>

Execute a given function func when the provided future future is completed. The future is not deferefenced outside the passed function to avoid spilling the exceptions.

See rejected C++ proposal for details: https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3721.pdf

Definition at line 40 of file KisFutureUtils.h.

42{
43 return std::async(std::launch::deferred,
44 [](std::future<T>&& future, Function&& func)
45 {
46 future.wait();
47 return std::forward<Function>(func)(std::move(future));
48 },
49 std::move(future),
50 std::forward<Function>(func)
51 );
52}

Variable Documentation

◆ unzip_wrapper

constexpr auto kismpl::unzip_wrapper
constexpr
Initial value:
= [] (auto f) {
return
[=] (auto &&x) {
return std::apply(f, std::forward<decltype(x)>(x));
};
}

Convert a given functor f accepting multiple arguments into a function that accepts a tuple with the same number of elements

Definition at line 70 of file KisMpl.h.

70 {
71 return
72 [=] (auto &&x) {
73 return std::apply(f, std::forward<decltype(x)>(x));
74 };
75};