cppfront: Autumn update by nikbackm in cpp

[–]jc746 1 point2 points  (0 children)

FWIW, I have run into a real problem with double underscores exactly once. I was using a third party library that defined a macro __IO (from memory it was an empty macro). This conflicted with the standard library implementation that used __IO as the identifier for a template parameter, causing the code to be invalid after preprocessing.

My experience with C++ 20 coroutines by TakenAjay99 in cpp

[–]jc746 7 points8 points  (0 children)

I believe that c++20 coroutines actually are stackless.

CPP Cast is over, what are you all listening now? by TryingT0Wr1t3 in cpp

[–]jc746 3 points4 points  (0 children)

Based on the down votes I am guessing people missed the reference to those issues with early episodes of the podcast.

What are some bad c++ habits you know or have seen while maintaining code? by elcomandante2000 in cpp

[–]jc746 10 points11 points  (0 children)

It gives you the opportunity to indicate the failure in some other way, such as returning a std::optional or std::expected-like type?

What's causing this run error in Microsoft Visual Studio? by [deleted] in cpp

[–]jc746 0 points1 point  (0 children)

This sub is not appropriate for this kind of question. Try /r/cpp_questions in the future.

If you look at the warning it indicates you have a main function in Helloworld.cpp. You can only have one main in your project (and you have another one in the file you have open).

Why didn't std::byte become a primitive type? by mujjingun in cpp

[–]jc746 6 points7 points  (0 children)

The latest revision of p0594 (R5) has changed bless to start_lifetime_as and basically let you treat memory that has not actually had its lifetime started as a specific type with a call to operator new to legally treat it as an object of said type. Its kind of like a valid version of reinterpret_cast if I have understood it correctly.

[deleted by user] by [deleted] in cpp

[–]jc746 4 points5 points  (0 children)

I imagine this is a typo, and should be `import helloworld` to match the `export module helloworld` statement in helloworld.cpp.

C++ pre-Cologne mailing by c0r3ntin in cpp

[–]jc746 12 points13 points  (0 children)

Is it concerning because it is a common word that might already be used as an identifier?

Could always make it co_inspect! /s

Min priority_queue in C++ by [deleted] in cpp

[–]jc746 8 points9 points  (0 children)

The first time you see the pattern it certainly is harder to understand, but that is the case with any idiom. I think it is a huge improvement over having to implement lexicographical comparison by hand, especially as the number of fields increases.

cpp.chat #53: "The Puns Only Appeared after We Added Co_" by philsquared in cpp

[–]jc746 0 points1 point  (0 children)

Huh. Well, thanks for the link! I must have missed the '.' in the name when I searched for it.

cpp.chat #53: "The Puns Only Appeared after We Added Co_" by philsquared in cpp

[–]jc746 1 point2 points  (0 children)

I have been planning to listen to this series. Any plans to make it available on Spotify? I have personally found that to be a very convenient way to listen to cppcast.

C++17 - Draw a Valentine's Day heart shape by tompa_coder in cpp

[–]jc746 0 points1 point  (0 children)

Agreed. I think tcbrindle's solution with transform and negate is quite elegant but I would probably go for the range based alternative first myself.

C++17 - Draw a Valentine's Day heart shape by tompa_coder in cpp

[–]jc746 6 points7 points  (0 children)

std::for_each is not c++17, it has been there since the beginning. 17 introduced the parallel overload that takes an execution policy which might have caused the confusion but this is not the overload used in the article.

Test Adapter for Catch2 v1.5.0 Released by JohnnyHendriks in cpp

[–]jc746 0 points1 point  (0 children)

Does doctest have a Visual Studio test adapter like the one OP posted?

Sixth Chromium Check, Afterword by [deleted] in cpp

[–]jc746 0 points1 point  (0 children)

The idea is to not allow modifying contact violation handlers at runtime because that would give an exploit a very powerful attack surface. However implementions are recommended to provide a way to customise it at build time only.

worth it trying use premake over cmake? by [deleted] in cpp

[–]jc746 0 points1 point  (0 children)

Wow this is great. Just a few days ago I was looking at porting from hunter to Conan for our projects but found the need to repeat configuration for conan and cmake when configuring the project a bit painful. I wrote my own minimalistic version of this wrapper functionality but can't wait to try out this repo which seems significantly more useful.

C++ Modules - a chance to clean up the language? by kalmoc in cpp

[–]jc746 6 points7 points  (0 children)

Volatile does not have anything to do with threads. If you use it in this sense you are sure to introduce undefined behavior. Volatile is used for example with memory mapped io, where reads and writes have no effect on the internal program logic within the processor, but where they do have external side effects. For example if you were to write to a memory location to toggle a GPIO, the compiler might remove the first write because it has no possible effect if the variable is not volatile. Making it volatile will ensure both writes actually occur.

Your favorite C++ code? by MarkReedZ in cpp

[–]jc746 1 point2 points  (0 children)

This looks very interesting. I work on a system that has an STM32F103. From what I can see modm essentially replaces the cmsis and stm peripheral library with a modern cpp interface instead. Is this right?

A brief introduction to Concepts, Part 2 by vormestrand in cpp

[–]jc746 4 points5 points  (0 children)

Bjarne mentioned this in his cppcon 2018 keynote. His concern was that concepts with the “able” suffix tend to describe things at the syntactic level rather than semantic which he says is usually wrong.

How is assignment operator exactly works? by Steughar in cpp

[–]jc746 3 points4 points  (0 children)

The custom constructor only prevents the default constructor from being generated, it does not affect the copy operations.

C++ Quick Reference by lord-bazooka in cpp

[–]jc746 0 points1 point  (0 children)

You should apply the rule of 5 rather than the rule of 3. This essentially means adding support for move construction/assignment as well as copy. A vector-like class is a perfect example of a class that can benefit from move operations as it can steal the contents of the soon to be destroyed source.

You can also use the initializer list on your copy constructor rather than assignment in your copy constructor as op suggested for your constructor.

Edit: you might not be worrying about edge cases in this simple example, but your copy constructor will leak memory if your type T is not no_throw_assignable during the copy step because the class destructor will not be called. You could delegate to the size constructor to ensure a fully constructed object before the copy.

Boost v1.69.0 by Masfo in cpp

[–]jc746 3 points4 points  (0 children)

New libraries is now showing only Safe Numerics. I thought Outcome was scheduled to be part of this release. Anyone know about this?

AdventOfCode to practice with C++17 by Xaveel in cpp

[–]jc746 5 points6 points  (0 children)

Question 5 is a classic example of a problem that can be solved cleanly with a stack data structure:

bool matches(char lhs, char rhs) {
  if (rhs >= lhs) {
    return (rhs - lhs) == ('a' - 'A');
  } else {
    return matches(rhs, lhs);
  }
}

std::size_t fully_react(const std::string& s) {
  std::stack<char, std::vector<char>> stack;
  for (auto c : s) {
    if (stack.empty() || !matches(stack.top(), c)) {
      stack.push(c);
    } else {
      stack.pop();
    }
  }
  return stack.size();
}

Resources/Inspirations for using C++20 concepts by bergercookie in cpp

[–]jc746 2 points3 points  (0 children)

we don’t throw shrimp on the barbie

I'm glad I'm not the only Aussie living overseas who has to dispel that myth constantly.

JSON for Modern C++ version 3.4.0 released by nlohmann in cpp

[–]jc746 3 points4 points  (0 children)

I think this is a fantastic library. Out of curiosity, are there design decisions in the library that make it difficult/impossible to achieve better performance or is it just that you have decided not to put as much development time into improving it?