kblib 0.2.3
General utilities library for modern C++
bits.h File Reference

Provides bit-manipulation functions and classes. More...

#include <algorithm>
#include <array>
#include <bitset>
#include <limits>
#include <memory>
#include <utility>
#include <vector>
#include <iostream>
#include "fakestd.h"
#include "simple.h"
#include "stats.h"
#include "tdecl.h"
#include "traits.h"
Include dependency graph for bits.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

class  kblib::detail_bits::trie_node< Key, Value >
 
class  kblib::compact_bit_trie< Key, key_range, Value >
 
struct  kblib::compact_bit_trie< Key, key_range, Value >::key_type
 
class  kblib::compact_bit_trie< Key, key_range, Value >::iterator_t< V >
 
struct  kblib::bitfield< offset, size, Storage >
 Implements a bitfield abstraction. May be used in a union with other bitfields. More...
 
struct  kblib::detail_bits::bitfield_proxy< Parent, ReturnT, Set, Get >
 A proxy reference type for BITFIELD-declared bitfields. More...
 
struct  kblib::detail_bits::pun_proxy< Type, Storage >
 
struct  kblib::detail_bits::array_pun_proxy< Type, Storage >
 
struct  kblib::detail_bits::array_filter< T >
 
struct  kblib::detail_bits::array_filter< T[N]>
 
struct  kblib::detail_bits::array_filter< T[]>
 
struct  kblib::detail_bits::array_filter2< T, S >
 
struct  kblib::detail_bits::array_filter2< T[N], S >
 
struct  kblib::detail_bits::array_filter2< T[], S >
 
struct  kblib::detail_bits::pun_el< P, Type, S, size_t, aliases >
 
struct  kblib::detail_bits::pun_el< P, Type[S], S, I, true >
 
struct  kblib::detail_bits::pun_el< P, Type[], S, I, true >
 
struct  kblib::detail_bits::punner_impl< S, std::index_sequence< Is... >, Types... >
 
struct  kblib::punner< Types >
 
struct  std::tuple_element< I, kblib::punner< Types... > >
 
struct  std::tuple_size< kblib::punner< Types... > >
 
class  kblib::union_pun< Type, Storage >
 
class  kblib::union_pun< Type[N], Storage >
 

Namespaces

namespace  kblib
 The main namespace in which all entities from kblib are defined.
 
namespace  kblib::detail_bits
 
namespace  std
 

Macros

#define KBLIB_INTERNAL_BITFIELD_MACRO(offset, size, name, raw)
 
#define BITFIELD(offset, size, name, raw)    KBLIB_INTERNAL_BITFIELD_MACRO(offset, size, name, raw)
 

Functions

constexpr auto kblib::memswap (unsigned char *A, unsigned char *B, std::size_t size) noexcept -> void
 Swaps memory ranges. More...
 
auto kblib::memswap (void *A, void *B, std::size_t size) noexcept -> void
 Swaps memory ranges. More...
 
template<std::size_t I, typename... Types>
auto kblib::get (punner< Types... > &p) noexcept -> decltype(auto)
 
template<std::size_t I, typename... Types>
auto kblib::get (const punner< Types... > &p) noexcept -> decltype(auto)
 
template<std::size_t I, typename... Types>
auto kblib::get (punner< Types... > &&p) noexcept -> decltype(auto)
 
template<std::size_t I, typename... Types>
auto kblib::get (const punner< Types... > &&p) noexcept -> decltype(auto)
 

Variables

template<typename Int >
constexpr int kblib::bits_of = std::numeric_limits<Int>::digits
 
template<typename... Types>
constexpr std::size_t kblib::detail_bits::max_size = std::max({sizeof(typename array_filter<Types>::type)...})
 

Detailed Description

Provides bit-manipulation functions and classes.

Author
killerbee
Date
2019-2021

Definition in file bits.h.

Macro Definition Documentation

◆ BITFIELD

#define BITFIELD (   offset,
  size,
  name,
  raw 
)     KBLIB_INTERNAL_BITFIELD_MACRO(offset, size, name, raw)

Defines appropriate member functions which operate on a bitfield. The generated functions are constexpr and optimize well.

Declare inside a struct to add a simulated bitfield to it. In total, 5 member functions will be defined, three of which are public. (The private two are required only to get around overload resolution problems with the proxy reference type.)

One is a const accessor, which returns the value of the field. One is a setter, which takes a new value for the field and assigns it, then returns the new value (after truncating it to the field width). The last function is the non-const accessor, which takes no argument and returns a proxy reference to the bitfield, which may be assigned to or implicitly converted to the value type.

Note
This macro is only defined if KBLIB_DEF_MACROS is true.
This macro always declares the member functions publically.
See also
See KBLIB_INTERNAL_BITFIELD_MACRO for definition.
Parameters
offsetThe number of bits less significant than this bitfield.
sizeThe number of bits in this bitfield.
nameThe name of the generated member functions which operate on this bitfield.
rawThe name of the member variable in which the bitfield is stored.

Definition at line 863 of file bits.h.

◆ KBLIB_INTERNAL_BITFIELD_MACRO

#define KBLIB_INTERNAL_BITFIELD_MACRO (   offset,
  size,
  name,
  raw 
)
See also
See BITFIELD(offset, size, name, raw) for documentation.
Note
This macro is defined unconditionally.
This macro resets the access level to public:

Definition at line 491 of file bits.h.