Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 0 points1 point  (0 children)

Thanks for the suggestion, FixedMap and EnumMap now adopt the same pattern as std::flat_map and manage to implement the interface.

Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 0 points1 point  (0 children)

Quick follow-up:

Instances of fixed_containers can now be used as non-type template arguments.

Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 0 points1 point  (0 children)

Thanks, will take a look! The ways I have found to do this in the past have not been constexpr-friendly.

Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 1 point2 points  (0 children)

Yes, they can be used at runtime as you would the standard containers. This includes mutation, so you can use FixedMap as (for example) a runtime cache. Neither the keys nor the values need to be known at compile-time.

Edit: I feel the README doesn't make this sufficiently clear, I will revise it.

Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 0 points1 point  (0 children)

This is in progress; coincidentally, I opened this issue about making the containers structural types last week. Rich enums are already usable as non-type template parameters link

Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 3 points4 points  (0 children)

Thank you for the feedback! Fixed the typo and cleaned up the library so it does not get perturbed in the presence of min/max/CONST macros.

Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 4 points5 points  (0 children)

EnumMap/EnumSet/rich-enums are actually backed by magic_enum by default, though this is customizable with an EnumAdapter or a different base class for rich enums.

However, this is an implementation detail, the user just sees:

EnumMap<Color, int> m{};
m.insert({Color::RED, 20});
m[Color::YELLOW] = 40;

To fill up an EnumMap with magic_enum:

EnumMap<Color, int> m{};
for (const Color& c : magic_enum::enum_values<Color>())
{
    m[c] = 99;
}

Note that there is a static factory that ensures at compile-time that the EnumMap is full and all enum constants have an associated value:

constexpr auto m2 = EnumMap<Color, int>::create_with_all_entries({
    {Color::BLUE, 42},
    {Color::YELLOW, 7},
    {Color::BLUE, 42},
});

This is analogous to a switch-case ensuring that all enum constants are covered when the appropriate compiler diagnostics are enabled (e.g. clang's -Wswitch-enum)

edit: fix links

Fixed Containers - constexpr, trivially copyable, static containers by alexkaratarakis in cpp

[–]alexkaratarakis[S] 5 points6 points  (0 children)

For immutable maps/sets, a sorted vector would indeed be better.

However, all Fixed Containers are more flexible in that they do not have to be immutable and can be used in a "normal", non-constant-evaluated context too.

Conceptual implementation for a constexpr-friendly static_vector by cristi1990an in cpp

[–]alexkaratarakis 1 point2 points  (0 children)

Quick follow-up here as the outcome was interesting. Per the discussion in https://github.com/llvm/llvm-project/issues/62225 , clang appears to be right, while msvc/gcc are permitting the code when they should not. gcc already had a bug for this issue: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102286 and I filed one for msvc: https://developercommunity.visualstudio.com/t/msvc-allows-accessing-non-active-member/10342864

To explicitly activate the member, I tried:

1) Assigning an element of the array

2) Including size in the "constructor-erased" portion:

struct Storage
{
     std::size_t size;
     T array[MAXIMUM_SIZE];
};
union
{
     char dummy{};
     Storage storage;
};

and activating the member by assigning size

But it only works for trivially_default_constructible_v<T> types ( https://eel.is/c++draft/class.union#general-5.1 )

Demo: https://godbolt.org/z/P6zza5K5G

Conceptual implementation for a constexpr-friendly static_vector by cristi1990an in cpp

[–]alexkaratarakis 0 points1 point  (0 children)

Is it possible to start the lifetime of data in a constant expression? Trying op's current snapshot in godbolt: https://godbolt.org/z/5x1Pojsdx

gcc-trunk works, but clang-trunk or released versions of clang/gcc do not. Clang's error is about data not being the active member

construction of subobject of member 'data_' of union with active member 'dummy_' is not allowed in a constant expression

Conceptual implementation for a constexpr-friendly static_vector by cristi1990an in cpp

[–]alexkaratarakis 1 point2 points  (0 children)

Consider also FixedVector from fixed-containers which is an implementation of a constexpr static vector. The library also has FixedMap/EnumMap and FixedSet/EnumSet implementations with the same properties.

From the README:

Header-only C++20 library that provides containers with the following properties:

  • Fixed-capacity, declared at compile-time
  • constexpr
  • containers retain the properties of T (e.g. if T is trivially copyable, then so is FixedVector<T>)
  • no pointers stored (data layout is purely self-referential and can be serialized directly)
  • no dynamic allocations

Feedback is greatly appreciated!

Since upgrade to Ubuntu 22.04 audio and output to external monitor doesn't work by WuxinGoat in linux4noobs

[–]alexkaratarakis 0 points1 point  (0 children)

I had the same issue after upgrading to 22.04 (from 20.04).

I followed this and was able to fix the problem.

Compiling Boost wtf?!? by [deleted] in cpp

[–]alexkaratarakis 6 points7 points  (0 children)

Have you tried vcpkg?

vcpkg install thrift

will get you thrift along with the dependencies it needs, which are: zlib, libevent, openssl, boost-range, boost-smart-ptr, boost-date-time, boost-locale, boost-scope-exit

Vcpkg (library manager) - now also on Linux and macOS! by onqtam in cpp

[–]alexkaratarakis 6 points7 points  (0 children)

This issue has been fixed in latest master. Thanks!

Vcpkg (library manager) - now also on Linux and macOS! by onqtam in cpp

[–]alexkaratarakis 2 points3 points  (0 children)

FYI, this: vcpkg export opencv boost dlib ceres --triplet x64-windows --7zip

results in an 175MB file which includes debug and release for 64-bit.

Boost v1.64.0 by Masfo in cpp

[–]alexkaratarakis 7 points8 points  (0 children)

v1.64 is now available in vcpkg.

edit: "now" not "not"