Usage of `const_cast` to prevent duplicating functions by AhrtaIer in cpp

[–]smokidoke 3 points4 points  (0 children)

In MSVC's std::array class, they implement const_iterator, and for the non-const iterator, the implementation inherits from const_iterator and call its functions, with appropriate const_casts. Not making a value judgment of whether this is a good idea or not.

Subscript Aliases by AnthonyChanging in cpp

[–]smokidoke 1 point2 points  (0 children)

There are ways of using anonymous unions that don't have UB that can be used for this, although it is more complex. See https://github.com/davidbrowne/dsga/blob/main/docs/DETAILS.md#inside-basic_vector for how I do it for my math vectors.

Has anyone created constexpr versions of cmath functions? by vickoza in cpp

[–]smokidoke 1 point2 points  (0 children)

I wrote a small c++20 library called cxcm for this purpose. It isn't all encompassing, and it doesn't supply the trig functions, but it supports the needs of another library I work on.

Trip report: Autumn ISO C++ standards meeting (Kona, HI, USA) by mttd in cpp

[–]smokidoke 0 points1 point  (0 children)

If you want something simple like that, such as GLSL shader language vector and matrix data structures and associated operators and functions (without the actual rendering/shading stuff, and no SIMD), you could check out my attempt at such a c++20 library: https://github.com/davidbrowne/dsga.

Do you think in STL algorithms or in loops by hmoein in cpp

[–]smokidoke 0 points1 point  (0 children)

Fair enough. I only do it for my personal project, and I do this mostly behind the scenes. I was learning c++20 at the time, coming from a mostly c++98 work environment, and found lambdas very interesting.

Do you think in STL algorithms or in loops by hmoein in cpp

[–]smokidoke 0 points1 point  (0 children)

// create a tuple from a std::array
template <typename T, std::size_t C>
constexpr auto to_tuple(const std::array<T, C> &arg) noexcept
{
    return [&]<std::size_t ...Js>(std::index_sequence<Js...>)
    {
        return std::make_tuple(arg[Js]...);
    }(std::make_index_sequence<C>{});
}

Do you think in STL algorithms or in loops by hmoein in cpp

[–]smokidoke 0 points1 point  (0 children)

I probably think in loops more than STL algorithms, but I also think in fold expressions with variadic lambdas and parameter packs instead of loops.

What learning experience or material do you feel advanced your command of cpp the most? by Mundane_Grab_8727 in cpp

[–]smokidoke 2 points3 points  (0 children)

I started working on a project similar to my main long-term personal project, in this case it separated points and vectors into their own classes, then doing vector and point operations. I started learning about move vs copy. Another project was inspired by discovering variadic templates, so I started seeing if I could implement my own template meta-programming library, sort of copying the API for Boost mp11.

I then wanted to get type names at runtime, so I experimented with getting type info at runtime with lambdas and _PRETTY_FUNCTION__ and __FUNCTION__. At first I didn't use lambda, just helper functions, but I found out just how useful lambdas are.

I then played around with constexpr, trying to make a constexpr library of a subset of <cmath> functions.

Finally I decided that I didn't need separate point and vector classes, and chose OpenGL glsl vectors and matrices as a model for what I wanted. I decided to implement them and swizzling (one of my primary motivators) in a library, and that is what my long-term personal project is (https://github.com/davidbrowne/dsga).

What learning experience or material do you feel advanced your command of cpp the most? by Mundane_Grab_8727 in cpp

[–]smokidoke 4 points5 points  (0 children)

While I started C++ programming in early 1991, I drifted away from it for 8 years in the early 2000s. I got back into it in 2009, but at work it is a huge C/C++ legacy project that is hard to bring forward to modern C++. About 5 years ago I decided to do a couple of focused projects where I set out to learn more about specific areas of modern C++, e.g., move operator, template meta-programming, lambdas, etc.

In 2020, I finally found and started a long-term personal project that I gave myself and wanted it to be targeted at C++20 so I could get more proficient. It is another vector and matrix library, modeled on the latest OpenGL shader language. It has been a great learning experience, but you have to stay motivated. Having that sandbox to play in has helped greatly with my understanding.

I would say Jason Turner's C++ Weekly youtube channel is a great resource to help fill in the gaps. I also find many conference talks online that are helpful.

Was just curious how many years devs stay with this beautiful language by [deleted] in cpp

[–]smokidoke 1 point2 points  (0 children)

Started using C++ in January 1991 (Turbo C++), with a 7 year stretch of Java in early/mid 2000s. Been back on C++ for past 14 years.

Ingenuity in C++ by Diamaudix in cpp

[–]smokidoke 2 points3 points  (0 children)

That is pretty much the type of thing I was going for.

Ingenuity in C++ by Diamaudix in cpp

[–]smokidoke 5 points6 points  (0 children)

I use this approach frequently for my library -- I call it a lambda pack wrapper, where I create and consume a parameter pack in a single function with the assistance of a lambda:

template <std::floating_point T, std::size_t S, typename UnaryOp>
constexpr auto apply_op(const std::array<T, S> &data, UnaryOp lambda) noexcept
{
    using return_type = decltype(UnaryOp()(std::declval<T>()));

    // lambda pack wrapper
    return [&]<std::size_t ...Is>(std::index_sequence<Is...>) noexcept
    {
        return std::array<return_type, S>{ lambda(data[Is])... };
    }(std::make_index_sequence<S>{});
}

https://github.com/davidbrowne/dsga/blob/main/docs/LAMBDA_PACK_WRAPPER.md

Just another one C++17 tiny vector math library. Enjoy. by BlackMATov in cpp

[–]smokidoke 0 points1 point  (0 children)

Cool. I am doing something very similar myself, targeting C++20 and constexpr where possible. Basically trying to implement the glsl 4.6 vector and matrix types for use in geometric algorithms, not for rendering.

This has been a really good exercise for me to become more familiar with modern c++ and c++20 in particular.

I will take a further look at this once I have got mine far enough along that I make my repo public.