GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing akrzemi1.wordpress.com — Andrzej's C++ blog Structured iterationIt 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/. A new blog locationI have decided to move Andrzej’s C++ blog to a new location. Event-driven flowsThis post is in response to two claims about coroutines:
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 → Concepts vs type traitsWhat is the difference between a concept and a type trait? Note that you can create a type trait using a template <typename T>
constexpr bool has_fun = requires(T v) {
v.fun();
};
You can also constrain a template with a type trait using a 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. Class invariantsThe 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 objectsSome 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 The obvious final stepThe 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:
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. A moved-from optionalThis post is in response to claims, that I have heard number of times, that the semantics of 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
Posted in programming
|
Tagged optional, performance, resource handling, value semantics
|
2 Comments
Local TimeIn 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 →
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
|
| 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. |