GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Home
  • About
  • C++ Glossary
  • Examples
  • 1. Examples — part 1
  • Reflection for aggregates
  • TCP Echo Server — coroutines
  • TCP Echo Server — lambdas
  • uncaught_exceptions and coroutines
  • Adobe.Poly — Counter
  • Adobe.Poly — Holder
  • Alternate list-initialization
  • Boost.TypeErasure — Counter
  • Boost.TypeErasure — Holder

This view

  • Original page
  • New address

GeezerVison is showing akrzemi1.wordpress.com — Andrzej's C++ blog

← Older posts

Structured iteration

Posted on December 3, 2025 by Andrzej Krzemieński

It is relatively easy to get your for-loops wrong. Luckily, C++ offers more and more bug-proof alternatives.

The post is available at the new blog location: https://thecppway.com/posts/structured_iteration/.

Posted in programming | Tagged correctness, idioms, ranges, stating intentions | Leave a comment

A new blog location

Posted on December 3, 2025 by Andrzej Krzemieński

I have decided to move Andrzej’s C++ blog to a new location.
It is now at https://thecppway.com and has been rebranded to The C++ way.
You will now get a more modest experience, but without disturbing advertisements and with the ability to comment using the markdown syntax.

Posted in Uncategorized | 2 Comments

Event-driven flows

Posted on November 16, 2025 by Andrzej Krzemieński

This post is in response to two claims about coroutines:

  1. Their reference function parameters may become dangling too easily.
  2. They are indistinguishable from regular functions from the declaration alone.

But rather than talking about coroutines, we will look at event-driven control flows in general. Modelling them is one of the primary motivations (alongside “generators”) for having coroutines. By understanding the need we will be better equipped to understand the tool. Continue reading →

Posted in programming | Tagged Boost, C++20, coroutines, gotchas, resource handling | 2 Comments

Concepts vs type traits

Posted on May 24, 2025 by Andrzej Krzemieński

What is the difference between a concept and a type trait? Note that you can create a type trait using a requires-expression:

template <typename T>
constexpr bool has_fun = requires(T v) {
  v.fun();
};

You can also constrain a template with a type trait using a requires-clause:

template <typename T>
  requires std::is_standard_layout_v<T>
void fun(T v);

There are differences though. Some are in the language, some in the tools, and one is human communication.

Continue reading →

Posted in programming | Tagged C++20, concepts, generic programming | 1 Comment

Class invariants

Posted on January 7, 2024 by Andrzej Krzemieński

The primary motivation for defining a class in C++ is to reflect and maintain a class invariant. In this post we will see what class invariants are and how you deal with them. Class invariants are important part of C++, even though there is no “invariant” keyword in C++. Continue reading →

Posted in programming | Tagged contracts, correctness, resource handling, stating intentions | 1 Comment

The double life of objects

Posted on December 18, 2023 by Andrzej Krzemieński

Some common knowledge: the lifetime of the object starts when its initialization is complete. Based on this we can get some further expectations: an object becomes const only after its initialization is complete. But this lifetime property of objects becomes blurred when copy elision comes into play. When a copy is elided, we have a situation where we would otherwise have two objects, each initialized separately, but now they are blended into one, its life time spanning across the caller and the calle, which has a number of surprising effects, receiving two initializations being one of them. Continue reading →

Posted in programming | Tagged advanced-c++, value semantics | 2 Comments

The obvious final step

Posted on April 23, 2023 by Andrzej Krzemieński

The title may be misleading, as I had to invent a new short term for the pattern that occurs in the code once in a while. Example first:

// write an element of an XML file

xml.begin_element("port");
xml.attribute("name", name);
xml.attribute("location", loc);
xml.end_element("port");  // <-- the obvious final step

During the construction of an XML file when you write an element, it is obvious that the last thing that you do is to write the closing tag. By obvious we mean:

  • Writing it down adds no new information (there is no other possible final instruction for this task).
  • It would be a bug if this instruction wasn’t there.

For this reason, people invent tools that allow expressing this type of business logic in a way that does not require of the programmer to write down the obvious final step. An oft used technique is to employ destructors. However, this is very difficult to get right and not implementable in general. In this post we will see why, and we will also see an alternative.

Continue reading →

Posted in programming | Tagged correctness, destructors, exception handling, idioms | 14 Comments

A moved-from optional

Posted on September 6, 2022 by Andrzej Krzemieński

This post is in response to claims, that I have heard number of times, that the semantics of optional’s move operations are wrong:

template <typename T>
void test(T v)
{
  optional<T> o = v;
  assert (o);     // o contains a value
  optional<T> p = std::move(o);
  assert (o);     // o still contains a value!
}

Some people are surprised that the second assert holds: the unfulfilled expectation is that moving from an optional should “eject” the value and leave the object in the state of not containing any value. While such semantics could be made to work, there are good reasons for preferring the present behavior. Continue reading →

Posted in programming | Tagged optional, performance, resource handling, value semantics | 2 Comments

Local Time

Posted on April 24, 2022 by Andrzej Krzemieński

In this post we will see how to solve the task from the previous post, but display the time point in local time instead of system time. The solution is simple and takes only two additional lines (you can scroll down towards the end), but I want to take this opportunity to offer some reflections about the concepts of time zones and daylight saving time. Continue reading →

Posted in programming | Tagged C++20, chrono | 6 Comments
← Older posts
  • Subscribe

    RSS Feed RSS - Posts

    RSS Feed RSS - Comments

  • Follow Andrzej's C++ blog on WordPress.com
  • Recent Posts

    • Structured iteration
    • A new blog location
    • Event-driven flows
    • Concepts vs type traits
    • Class invariants
  • Archives

    Archives
  • Blogroll

    • // info
    • Alf on programming
    • Anthony Williams's blog
    • Asymmetric Transfer
    • Bannalia
    • Bartosz Milewski's Cafe
    • Boris Kolpackov
    • C++ Truths
    • Corensic
    • Eric Niebler
    • Fluent {C++}
    • Functional C++
    • isocpp.org
    • Marshall's C++ Musings
    • Meeting C++
    • Musing Dragoman
    • Optimizing C++ Code
    • Preshing on Programming
    • Scrupulous Abstractions
    • Simplify C++!
    • Stefanus Du Toit's Blog
    • Sutter’s Mill
    • Tales of C++
    • Tom Honermann, C++ minion
    • Train of thoughts on C++
    • [Un]defined behavior
  • C++ Links

    • ACCU Overload
    • Alex Stepanov's Papers
    • Bjarne Stroustrup's homepage
    • Boost Library Incubator
    • Boost's homepage
    • C++ Annotations
    • C++ Core Guidelines
    • C++ FAQ @ isocpp.org
    • C++ Standards Committee — LWG
    • Flaming Dangerzone
    • FPComplete
    • Guru Of The week
    • Howard Hinnant's page
    • ISO C++ Standard – Discussion
    • ISO C++ Standard – Future Proposals
    • Matthew Wilson's work
    • SGI STL
    • Standard C++ Foundation
    • STL Programmer's Guide
    • The C++ Standards Committee
    • Thomas Becker's
    • Wikipedia on C++11
  • C++ Videos

    • CppCon
    • Efficient Programming with Components
    • GoingNative
    • Programming Conversations
Andrzej's C++ blog
Blog at WordPress.com.
Privacy & Cookies: This site uses cookies. By continuing to use this website, you agree to their use.
To find out more, including how to control cookies, see here: Cookie Policy
  • Subscribe Subscribed
  • Andrzej's C++ blog
    View site in Reader
    Manage subscriptionsSign upLog in
    Report this content
    Collapse this bar
Loading Comments...
Create your own website, free on WordPress.com.Create your own website.
Start free
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.