All Projects → foonathan → Type_safe

foonathan / Type_safe

Licence: mit
Zero overhead utilities for preventing bugs at compile time

Projects that are alternatives of or similar to Type safe

typed
Typed variables for PHP 7.4+ ( don't use this please )
Stars: ✭ 66 (-92.38%)
Mutual labels:  type-safety
Vuex Smart Module
Type safe Vuex module with powerful module features
Stars: ✭ 306 (-64.67%)
Mutual labels:  type-safety
Gentype
Auto generation of idiomatic bindings between Reason and JavaScript: either vanilla or typed with TypeScript/FlowType.
Stars: ✭ 683 (-21.13%)
Mutual labels:  type-safety
nest-typed-config
Intuitive, type-safe configuration module for Nest framework ✨
Stars: ✭ 47 (-94.57%)
Mutual labels:  type-safety
Scalacss
Super type-safe CSS for Scala and Scala.JS.
Stars: ✭ 293 (-66.17%)
Mutual labels:  type-safety
Structopt
Parse command line arguments by defining a struct
Stars: ✭ 323 (-62.7%)
Mutual labels:  type-safety
coalton
Coalton is an efficient, statically typed functional programming language that supercharges Common Lisp.
Stars: ✭ 439 (-49.31%)
Mutual labels:  type-safety
Flow Runtime
A runtime type system for JavaScript with full Flow compatibility.
Stars: ✭ 813 (-6.12%)
Mutual labels:  type-safety
Mammoth
A type-safe Postgres query builder for TypeScript.
Stars: ✭ 305 (-64.78%)
Mutual labels:  type-safety
Swift Nonempty
🎁 A compile-time guarantee that a collection contains a value.
Stars: ✭ 585 (-32.45%)
Mutual labels:  type-safety
Cone
Cone Programming Language
Stars: ✭ 257 (-70.32%)
Mutual labels:  type-safety
Identity
🆔 Type-safe identifiers in Swift
Stars: ✭ 282 (-67.44%)
Mutual labels:  type-safety
Graphaello
A Tool for Writing Declarative, Type-Safe and Data-Driven Applications in SwiftUI using GraphQL
Stars: ✭ 355 (-59.01%)
Mutual labels:  type-safety
postgresql-typed
Haskell PostgreSQL library with compile-time type inference
Stars: ✭ 72 (-91.69%)
Mutual labels:  type-safety
Nexus Plugin Prisma
A plugin for Nexus that integrates Prisma
Stars: ✭ 728 (-15.94%)
Mutual labels:  type-safety
llvm-hs-typed
Type Safe LLVM IR ( Experimental )
Stars: ✭ 47 (-94.57%)
Mutual labels:  type-safety
Jni.hpp
A modern, type-safe, header-only, C++14 wrapper for JNI
Stars: ✭ 313 (-63.86%)
Mutual labels:  type-safety
Pcf Nominal
A formalisation of PCF in Agda using naive nominal binding
Stars: ✭ 5 (-99.42%)
Mutual labels:  type-safety
Swift Tagged
🏷 A wrapper type for safer, expressive code.
Stars: ✭ 801 (-7.51%)
Mutual labels:  type-safety
Topshell
TopShell - a purely functional, reactive scripting language
Stars: ✭ 422 (-51.27%)
Mutual labels:  type-safety

type_safe

Project Status Build Status

type_safe provides zero overhead abstractions that use the C++ type system to prevent bugs.

Zero overhead abstractions here and in following mean abstractions that have no cost with optimizations enabled, but may lead to slightly lower runtime in debug mode, especially when assertions for this library are enabled.

The library features cannot really explained in the scope of this readme, I highly suggest that you check out the first and second blog post and the examples.

Sponsored by Embarcadero C++Builder.

If you like this project, consider supporting me.

Features

Improved built-in types

  • ts::integer<T> - a zero overhead wrapper over a built-in integer type
    • no default constructor to force meaningful initialization
    • no "lossy" conversions (i.e. from a bigger type or a type with a different signedness)
    • no mixed arithmetic/comparison with floating points or integer types of a different signedness
    • over/underflow is undefined behavior in release mode - even for unsigned integers, enabling compiler optimizations
  • ts::floating_point<T> - a zero overhead wrapper over a built-in floating point
    • no default constructor to force meaningful initialization
    • no "lossy" conversion (i.e. from a bigger type)
    • no "lossy" comparisons
    • no mixed arithmetic/comparison with integers
  • ts::boolean - a zero overhead wrapper over bool
    • no default constructor to force meaningful initialization
    • no conversion from integer values
    • no arithmetic operators
  • aliases like ts::uint32_t or ts::size_t that are either wrapper or built-in type depending on macro
  • literal operators for those aliases like 342_u32 or 0_usize

Vocabulary types

  • ts::object_ref<T> - a non-null pointer
  • ts::index_t and ts::distance_t - index and distance integer types with only a subset of operations available
  • ts::array_ref<T> - non-null reference to contigous storage
  • ts::function_ref<T> - non-null reference to a function
  • ts::flag - an improved flag type, better than a regular bool or ts::boolean
  • ts::flag_set<Enum> - a set of flags
  • ts::output_parameter<T> - an improved output parameter compared to the naive lvalue reference

Optional & Variant

  • ts::basic_optional<StoragePolicy> - a generic, improved std::optional that is fully monadic, also ts::optional<T> and ts::optional_ref<T> implementations
  • ts::compact_optional implementation for no space overhead optionals
  • ts::basic_variant<VariantPolicy, Types...> - a generic, improved std::variant, also ts::variant and ts::fallback_variant implementations

Type safe building blocks

  • ts::constrained_type<T, Constraint, Verifier> - a wrapper over some type that verifies that a certain constraint is always fulfilled
    • ts::constraints::* - predefined constraints like non_null, non_empty, ...
    • ts::tagged_type<T, Constraint> - constrained type without checking, useful for tagging
    • ts::bounded_type<T> - constrained type that ensures a value in a certain interval
    • ts::clamped_type<T> - constrained type that clamps a value to ensure that it is in the certain interval
  • ts::strong_typedef - a generic facility to create strong typedefs more easily
  • ts::deferred_construction<T> - create an object without initializing it yet

Installation

Header-only, just copy the files in your project. You need to add the type_safe include directory to your include path as well as make debug_assert.hpp available. The repository is included. You also need to enable C++11.

Behavior can be customized with the following macros:

  • TYPE_SAFE_ENABLE_ASSERTIONS (default is 1): whether or not assertions are enabled in this library
  • TYPE_SAFE_ENABLE_WRAPPER (default is 1): whether or not the typedefs in type_safe/types.hpp use the wrapper classes
  • TYPE_SAFE_ARITHMETIC_POLICY (ub/checked/default, default is ub): whether under/overflow in the better integer types is UB, an exception, or the default behavior

If you're using CMake there is the target type_safe available after you've called add_subdirectory(path/to/type_safe). Simply link this target to your target and it will setup everything automagically. For convenience the macros are also mapped to CMake options of the same name.

Documentation

You can find the full documentation generated by standardese here.

Acknowledgements

This project is greatly supported by my patrons. In particular thanks to the individual supporters:

  • Mark Atkinson
  • Reiner Eiteljörge

And big thanks to the main contributors as well:

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].