fa
Feedback
C++ - Reddit

C++ - Reddit

رفتن به کانال در Telegram

Stay up-to-date with everything C++! Content directly fetched from the subreddit just for you. Join our group for discussions : @programminginc Powered by : @r_channels

نمایش بیشتر
227
مشترکین
-124 ساعت
-27 روز
-130 روز
آرشیو پست ها
Move variadic template arguments from a template structure to another template structure I'm in a bottomless pit of over-engineering that I don't want to get our out because it's way too much fun. Also, you can't go outside so what else is there to do. Here is a really cool thing I found. I wanted to use my fancy compile-time alias for calculating summary byte size of multiple structures: template<class ... Descriptions> using summarybytesize = std::integralconstant<sizet, (Descriptions::bytesize::value + ...)>; It's not `sizeof()` because it's a description of data, not actual data. It carries no data, ok? Basically there are types that have required `bytesize defined which is an integralconstant` as well. Problem is, I wanted to use it with a subset (first N actually) of variadic template arguments that I had. So I couldn't simply `Args...` them to this structure :( In moments like this you really want to think `std::tuple` so I did that. I made `std::tuple<Args...>`, then I put it into thing below to get `std::tuple` of only N first types from initial tuple: template<std::sizet Count, typename Head, typename ... Rest> struct tupleoffirstn { using type = decltype(std::tuplecat(std::declval<Head>(), std::tuplecat(std::declval<Rest>()...))); }; template<typename Head, typename ... Rest> struct tupleoffirstn<0, Head, Rest...> { using type = Head; }; Now - the actual core of this whole thing. How do I extract tuple types and push it to my summary_byte_size<> struct? How to get Ts... from Something<Ts...>? Introducing - this abomination: template<typename Source, template <typename...> typename Target> struct extracttypesandapply{}; template<template <typename...> typename Source, template <typename...> typename Target, typename ... Ts> struct extracttypesandapply<Source<Ts...>, Target> { using type = Target<Ts...>; }; Basically we force it to pick specialized version so that Ts... is deduced and I can freely push it to anything I want that can accept these given Ts... args. And there we go! auto totalSize = extracttypesandapply<std::tuple<Vec3, Vec3, Vec2>, summarybytesize>::type::value; Here's another example how you can use it. It can be used to take a container and create another container with same type! Here I made `std::list<int>` from `std::vector<int>`: auto actualList = extracttypesandapply<std::vector<int>, std::list>::type(); Here's Godbolt link if you want - https://godbolt.org/z/zO711Q If you want to pass values through template args like std::size_t then it's whole different story, because neither typename nor class is std::size_t... but it works for types! Also, this is C++17. In C++20 you can basically do the same using single line templated lambda: [&]<class ... Types>(std::tuple<Types...>){ /* use Types... however pleased */ }(tuple_of_first_n<2, std::tuple<int, char, int, int>>::type{}); I hope you like it :D https://redd.it/mtblkb @r_cpp

Stroustrup on value categories I discovered this gold and I thought whoever has (like me) a problem in dismantling all those complex notions of lvalues, rvalues, prvalues, xvalues etc, could be enlightened by these sketchy (and divine) notes by Him. https://redd.it/ms7puh @r_cpp

xbow: range-v3 actions and ranges for Arrow C++ https://github.com/seertaak/xbow https://redd.it/mswno0 @r_cpp

Discussion: Should newer generic code relies on less-than comparison or 3-way comparison? Consider this first draft of a generic algorithm: template <class ContainerType, class ValueType> constexpr std::optional<typename ContainerType::iterator> insert_sorted_unique(ContainerType& c, ValueType&& v) { using std::begin; using std::end; const auto insertionPoint = std::lower_bound(begin(c), end(c), v); if (insertionPoint == end(c) || !(*insertionPoint == v) ) return c.insert(insertionPoint, std::forward<ValueType>(v)); else return std::nullopt; } The plan for the second draft is to add a third parameter for taking comparison function. My question is, should the comparison function be less-than comparison like we've always do, or 3-way comparison as we now have spaceship operator? - If we choose less-than, the `*insertionPoint == v` part will be changed to two less-than comparisons. - If we choose 3-way, we'll need an adapter for passing the comparison function since `std::lower_bound` still uses less-than comparison. - An argument for preferring less-than is compatibility to existing convention for weak ordering. - An argument for 3-way is, 3-way comparison provides more information, including whether the ordering is weak ordering or total ordering or something. And a broader question beyond this specific example is: Should newer generic code relies on less-than comparison or 3-way comparison? What's do you think? https://redd.it/msn9s6 @r_cpp

apecs: A petite entity component system Hey all, In my spare time I've been working on a small game engine project, and as part of that I decided to design my own ecs. The API for it is heavily inspired by EnTT, with the main difference being that all component types need to be declared up front. My main motivation for doing this was to have a play around with variadic templates and metaprogramming, as well as C++20 coroutines which I've used to implement all the iteration. I don't expect it to be used by others as there are many better choices, but I'd be interested in hearing some feedback and critique. Library: https://github.com/MagicLemma/apecs https://redd.it/mst4cg @r_cpp

I tried to define how checked exceptions could work in C++. Feedback/help welcome! https://github.com/MakersF/cpp-checked-exceptions https://redd.it/mstdb7 @r_cpp

<charconv> from Microsoft STL, but multi-platform https://github.com/iboB/mscharconv https://redd.it/msrus5 @r_cpp

Hello, I have recently begun to follow a 4-hour course on C++ and I wanna make sure that I'm not missing anything important or if I am doing something wrong or inefficiently. I have been taking notes on what I am learning as I go along, can a few people go in there and lend me some feedback on my no https://www.youtube.com/watch?v=vLnPwxZdW4Y https://redd.it/msl8wx @r_cpp

zpp::throwing<T> - Implementing "almost" C++ exceptions with coroutines https://github.com/eyalz800/zpp_throwing https://redd.it/msg53x @r_cpp

Flashlight - A C++ standalone library for machine learning. Open-sourced by Facebook. https://github.com/flashlight/flashlight https://redd.it/msb8kv @r_cpp

Results summary: 2021 Annual C++ Developer Survey "Lite" [PDF] http://isocpp.org/files/papers/CppDevSurvey-2021-04-summary.pdf https://redd.it/ms6ier @r_cpp

Andreas Fertig - C++ Insights - How stuff works, C++20 and more! - Meeting C++ online https://www.youtube.com/watch?v=3M77F-u3mjI https://redd.it/ms5ujr @r_cpp

Announcing Eclipse iceoryx 1.0.0 Yesterday we had our first major release of Eclipse iceoryx, a true zero-copy inter-process-communication middleware that enables virtually limitless data transfer in constant time. It has its origins in the automotive industry, where large amounts of data have to be transferred between different processes, e.g. in driver assistance or automated driving systems. These efficient communication mechanisms can also be applied to a wider range of use cases, e.g. in the field of robotics or game development. github: https://github.com/eclipse-iceoryx/iceoryx homepage: https://iceoryx.io iceoryx in 1000 words: https://www.eclipse.org/community/eclipse\_newsletter/2019/december/4.php ROS2: https://github.com/ros2/rmw\_iceoryx/pull/42 https://redd.it/ms2i0f @r_cpp

Another C++ unit testing framework without macros Just sharing a C++ unit testing framework I wrote recently. Currently it requires C++17, but aim is to switch to C++20 when it becomes widely supported. It is in Alpha version right now. Would be nice to hear thoughts/critics/any feedback about it. https://github.com/cppfw/tst https://redd.it/ms2nal @r_cpp

I have been getting serious about privacy and looking for a privacy focused CPP IDE I have always used MS VS and I was wondering if anyone can recommend an open source that might be better ? Reason I stuck with MS VS is because of Unreal Engine and how well they work together https://redd.it/mrvpzv @r_cpp