Cross-platform STL-styled and STL-compatible library with implementing containers, ranges, iterators, type traits and other tools; actors system; type-safe config interface.

Yato

A small repository where I'm gatherting useful snippets and abstractions for C++ development.

Yato includes 3 main modules: multidimensional containers and utils, actors system, and type-safe config.

If you find any bug, please feel free to submit an issue! It will be very helpful for me.

Licence

Copyright 2016-2020 Alexey Gruzdev

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Build/Install

The library consists of only headers, so it doesn't require build. The repository provides sources for some tests sources that can be configured and built with the help of cmake file. In order to build the tests you will need to add directory of googletest to the cmake (GoogleTest repository)

Currently the library can be successfully built by the following compilers:

  • MSVC 2019
  • MSVC 2017
  • MinGW 9.3
  • Clang 11.0.0 (x86_64-pc-windows-msvc)
  • Clang 11.0.0 (x86_64-mingw32)
  • GCC 8.2
  • Android (llvm, NDK 21)

Description

Actors system

Yato provides a simple actors system implementation, that is developed to look and feel like Akka. It supports basic features of an actor system and optional io model for networking.

More...

Type support

Yato library provides a set of additional type traits

  • yato::is_shared_ptr / yato::is_unique_ptr - chech if type is a smart pointer
  • yato::is_same - extended version of std::is_same checking that any number of types are same
  • yato::one_of - checks that type is one of the number of types
  • yato::function_trait - gets return type and all argument types of a function or function member

Also there are additional tools for working with types. The library provides literals for fixed size types (_u8, _u16, etc.) if user defined literals are supported by compiler. Additional casts are provided:

  • yato::narrow_cast - casts one arithmetic type to another. If correct value was lost due to narrowing then it throws exception in debug build
  • yato::pointer_cast - performs reinterpret casting for pointers. Saves CV-cvalifiers and doens't allow to cast intergral value to pointer

Functional traits

  • yato::is_callable - checks if type is a callable type, i.e. it is pointer to function or it has operator() (including closure type)
  • yato::callable_trait - deduces return type and all arguments types for any callable type
  • yato::make_function - converts any callable type to std::function with corresponding return and arguments types

Type matching

yato::match performs compile time matching of variable type based on function overloading mechinism

"Annotations"

There are a couple of experiments inspired by Cpp Core Guidelines

  • yato::not_null - pointer wrapper preventing from passing null pointer
  • yato::instance_of - pointer wrapper checking the dynamic type of passed pointer

Ranges

yato::range - aggregator of a couple of iterators simplifing passing two iterators to functions, returning iteratos from functions, hepling to hold iterators of one container together. Can be ued in ranged for expressions. Together with yato::numeric_iterator the range can represent a sequence of integer numbers without actual storing them

Range provides the following functional style operations:

  • map - returns a range of yato::transform_iterator lazily applying a function to the each element of the range
  • filter - returns a range of yato::filter_iterator lazily selecting only those elements of the range which satify some predicate
  • zip - returns a range of yato::zip_iterator joining the range with other ranges into a range of tuples
  • fold_left - accumulates all elements of the range applying some binary operation from the left to the right
  • fold_right - accumulates all elements of the range applying some binary operation from the right ot the left

Containers

Yato implemets a number of general purpose containers:

  • yato::array_nd - multidimensional static array with interface and behaviour similar to std::array; The layout and size of the yato::array_nd are equal to native multidimensional array ( T[ ][ ]... )
  • yato::vector_nd - multidimensional dynamic array similar to std::vector; It supports dynamic adding/removing of elements and provides similar interface to std::vector
  • yato::array_view / yato::array_view_nd - non-owning containers which can be attached to any source of data and treat it similar to one-/multi-dimensional array
  • yato::vector_view - non-owning one-dimensional container providing an interface similar to std::vector for a fixed memory buffer

Reflection

WIP

Current implementation allows to reflect classes and data fields Reflection information allows to get a list of data fields and its types in compile time, iterate over all data fields and get pointers to fields in run-time

Tuple algorighms

Yato library provides few compile time algorithms on tuples

  • tuple_transform - applies unary function to all tuple elements (or binary function to elements of two tuples) and returns tuple with result values
  • tuple_for_each - calls unary function for the each tuple element
  • tuple_all_of - checks if unary predicate returns true for all elements of the tuple (or binary predicate for all elements of two tuples)
  • tuple_any_of - checks if unary predicate returns true for at least one element of the tuple (or binary predicate for at least one element of two tuples)

Iterators

  • yato::numeric_iterator enumerates sequental integer values allowing to iterate over an integer sequence witout storing it
  • yato::zip_iterator is an analogue of boost::zip_iterator but implemented in terms of modern C++ in order to get rid of any boost dependency
  • yato::transform_iterator is an analogue of boost::transform_iterator but implemented in terms of modern C++ in order to get rid of any boost dependency
  • yato::filter_iterator is an analogue of boost::filter_iterator but implemented in terms of modern C++ in order to get rid of any boost dependency

Allocator

  • yato::aligning_allocator is STL-compatible allocator aloowing to alloc heap memory with any alignment. Alignments which are not power of 2 or bigger than alignment of std::max_align_t will have small memory overhead

Type safe wrappers

  • yato::any type safe wrapper for any type. Is similar to std::any or boost::any, but this implementation supports non-copyable and non-movable types as well
  • yato::any_ptr type safe wrapper for any pointer (i.e. void*)
  • yato::variant type safe wrapper for a specified alternativies. Similar to std::variant but can't have empty state. If empty state is necessary, then void should be in alternatives list

Cast between variants with different sets of alternatives can be made with the help of yato::variant_cast.

There provided effective matchers for yato::any and yato::variant allowing to handle stored value in swicth style. If no match is found then default case is called (yato::match_default_t) if defined, otherwise the exception yato::bad_match_error is thrown.

  • yato::any_match matches stored value of yato::any
  • yato::variant_match matches stored value of yato::variant

Attributes interface

yato::attributes_interface is interface class allowing to add arbitrary attributes to a class instance (as key-value pair). Attributes are completely generic and are passed as yato::any. Only the concrete implementation is able to take or discard passed attribute. Is useful for passing parameters to very different types in one hierarchy so that base classes don't know about parameters types.

There are few generic implementations

  • yato::attributes_map accepts any attributes and stores in std::map. Is not thread safe
  • yato::ignores_attributes ignores any attributes passed to the class.
  • yato::atomic_attributes accepts a number of previously registered attributes. All opetarions with the attrinutes are atomic and thread safe (except for registration). Supports only arithmetic types or pointers

Extras

  • yato.natvis provides user-friendly visualization of yato::vector_nd and yato::array_view_nd classes (1d,2d and 3d) in Visual Studio debugger.

Acknowledges

The project is developed with the help of JetBrains tools for Open Source

JBLogo

Similar Resources

An open source initiative for implementing and testing algorithms in various programming languages.

Algorithms An open source initiative for implementing and testing algorithms in various programming languages. Contributing The idea here is to learn

Nov 28, 2021

Implementing B tree using C++

Implementing B tree using C++

B Tree Implementing B tree using C++ Search Insert Structuring the main Function Delete Demo : Usage : Clone it to some place in your PC. Install Visu

Nov 27, 2021

Implementing dynamic lists in C begginer level

Dynamic-Lists Implementing dynamic lists in C begginer level DESCRIPTION: This header file list.h implements python-like lists and it's functions.

Feb 2, 2022

A family of header-only, very fast and memory-friendly hashmap and btree containers.

A family of header-only, very fast and memory-friendly hashmap and btree containers.

The Parallel Hashmap Overview This repository aims to provide a set of excellent hash map implementations, as well as a btree alternative to std::map

Jan 9, 2023

Allocator Aware Containers Made Easy

Custom Allocator Aware containers made easy with "wit" Have you ever looked at the allocator specification and thought about how hard it would be to

Sep 25, 2021

libsrt is a C library for writing fast and safe C code, faster.

libsrt is a C library for writing fast and safe C code, faster. It provides string, vector, bit set, set, map, hash set, and hash map handling. Suitable for soft and hard real-time. Allows both heap and stack allocation. *BETA* (API still can change: suggestions are welcome)

Dec 24, 2022

Step is a C++17, header-only library of STL-like algorithms and data structures

Step is a C++17, header-only library of STL-like algorithms and data structures

Step is a C++17, header-only library of STL-like algorithms and data structures. Installation git clone --depth 1 https://github.com/storm-ptr/step.gi

Sep 1, 2022

A C++20 implementation of safe (wrap around) integers following MISRA C++ rules

PSsimplesafeint A C++20 implementation of safe (wrap around) integers following MISRA C++ rules. I might also work on a C++17 implementation, but this

Aug 15, 2022

Cross-platform process memory inspector

Cross-platform process memory inspector

Catsight Cross-platform process memory viewer inspired by x64dbg. Features Cross-platform (currently runs on Linux and Windows). Attach to any process

Dec 23, 2022
Comments
  • broadcast view

    broadcast view

    It would be nice to see support of broadcasting view (https://pytorch.org/docs/stable/notes/broadcasting.html) for yato::vector_nd / yato:array_view_nd

  • Make Yato a library type target in cmake

    Make Yato a library type target in cmake

    Why not to use

    add_library(Yato INTERFACE)
    

    instead of add_custom_target ?

    https://cmake.org/cmake/help/latest/command/add_library.html#interface-libraries

Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).
Library of generic and type safe containers in pure C language (C99 or C11) for a wide collection of container (comparable to the C++ STL).

M*LIB: Generic type-safe Container Library for C language Overview M*LIB (M star lib) is a C library enabling to use generic and type safe container i

Jan 5, 2023
C++ Type Traits for Smart Pointer
C++ Type Traits for Smart Pointer

SmartPointerTypeTrait C++ Type Traits for Smart Pointer is_a_pointer is_smart_pointer template < typename T > struct is_smart_ptr : is_smart_ptr_impl<

Sep 14, 2022
A Binary Genetic Traits Lexer

BinLex a Genetic Binary Trait Lexer Library and Utility The purpose of BinLex is to extract basic blocks and functions as traits from binaries. Most p

Dec 26, 2022
A library of type safe sets over fixed size collections of types or values, including methods for accessing, modifying, visiting and iterating over those.

cpp_enum_set A library of type safe sets over fixed size collections of types or values, including methods for accessing, modifying, visiting and iter

Jun 16, 2022
Easy to use, header only, macro generated, generic and type-safe Data Structures in C
Easy to use, header only, macro generated, generic and type-safe Data Structures in C

C Macro Collections Easy to use, header only, macro generated, generic and type-safe Data Structures in C. Table of Contents Installation Contributing

Jan 8, 2023
Eggs.Variant is a C++11/14/17 generic, type-safe, discriminated union.

Eggs.Variant Introduction Eggs.Variant is a C++11/14/17 generic, type-safe, discriminated union. See the documentation at http://eggs-cpp.github.io/va

Dec 3, 2022
A collecton of generic reference counted data structures, tools to create compatible C style classes, and demo applications

The Offbrand library is a collection of reference counted generic data structures written in C for C. The library includes bash scripts to assist in t

Dec 10, 2022
A C++ data container replicating std::stack functionality but with better performance than standard library containers in a stack context.

plf::stack A data container replicating std::stack functionality but with better performance than standard library containers in a stack context. C++9

Sep 11, 2022
Strong typedef - A class template that creates a new type that is distinct from the underlying type, but convertible to and from it

jss::strong_typedef <Tag, ValueType, Properties...> This is an implementation of a C++17 class template that provides a wrapper type that is convertib

Dec 21, 2022