Skip to content

Instantly share code, notes, and snippets.

Corner cases in std::optional initialization

It has been one year since my previous post: Initialization in C++: A corner case. In this post, I would like to share some corner cases (with implementation divergences) encountered while testing std::optional's constructors. To maximize flexibility and usability, std::optional provides a rich set of overloaded constructors, along with some heavy SFINAE logic to disambiguate them.1 The downside is that certain forms of initialization may behave unexpectedly. In the following sections, I will present several examples and explain how they are interpreted by various implementations and by the C++ standard. All references to the standard are to N4950 (the C++23 final draft).

Introduction

First, let's write down the re

Footnotes

  1. This topic is discussed in detail in Barry's post: Getting in trouble with mixed construction.

@guiodic
guiodic / Plasma-X11-improved.md
Last active August 21, 2025 03:35
Improved Plasma X11 experience

This guide is to improve the KDE Plasma experience on X11. It particularly applies to those using the modesetting driver (mainly Intel graphics cards)

Install Xorg-git or Xlibre

This is a crucial step. XLibre and xorg-git contain the "TearFree" feature for modesetting, which is not available in the standard releases. If you use a driver other than modesetting, check that the TearFree option exists for your driver.

Installation depends on the distribution you use. On Arch Linux and derivatives:

Xorg-git:

As a work colleague asked me about how I setup my "multi-live-system-thumbdrive": As a base I installed https://grml.org/ but I am sure another system using grub2 would also work. This installed grub on my USB thumbdrive with a rather simple main grub.cfg:

## grub2 configuration
source /boot/grub/header.cfg

insmod regexp

for config in /boot/grub/*_default.cfg ; do source "$config" ; done
for config in /boot/grub/*_options.cfg ; do source "$config" ; done
@Aerocatia
Aerocatia / PKGBUILD
Last active September 1, 2021 16:38
Arch Linux mingw-w64-harfbuzz 2.9.0
# Maintainer: pingplug < aur at pingplug dot me >
# Contributor: Schala Zeal < schalaalexiazeal at gmail dot com >
_commit=9aa6f8a93f035dd0a1e3978da495d830049480c8 # tags/2.9.0
_architectures="i686-w64-mingw32 x86_64-w64-mingw32"
pkgbase=mingw-w64-harfbuzz
pkgname=('mingw-w64-harfbuzz' 'mingw-w64-harfbuzz-icu')
pkgver=2.9.0
pkgrel=2
#!/usr/bin/python3
import argparse
import os
import os.path
import pathlib
import struct
import sys
import fileinput

Paste text on VNC terminal that don't allow copy-paste

  • Prepare script on terminal
  • Copy data
  • Run script
  • Move focus to destination target
  • Script will 'type' for you
@shakna-israel
shakna-israel / LetsDestroyC.md
Created January 30, 2020 03:50
Let's Destroy C

Let's Destroy C

I have a pet project I work on, every now and then. CNoEvil.

The concept is simple enough.

What if, for a moment, we forgot all the rules we know. That we ignore every good idea, and accept all the terrible ones. That nothing is off limits. Can we turn C into a new language? Can we do what Lisp and Forth let the over-eager programmer do, but in C?


@brasey
brasey / Configure systemd-resolved to use a specific DNS nameserver for a given domain.md
Created October 25, 2019 14:38
Configure systemd-resolved to use a specific DNS nameserver for a given domain

Configure systemd-resolved to use a specific DNS nameserver for a given domain

Use case

Given

  • I use a VPN to connect to my work network
  • I'm on a Linux computer that uses systemd-resolved
  • I have a work domain called example.com
  • example.com is hosted by both public and private DNS nameservers
@RajithaKumara
RajithaKumara / LocalServerSocket.md
Created September 20, 2019 13:45
Android create Unix domain socket by bound file descriptor

Android create Unix domain socket by bound file descriptor

Android provide LocalServerSocket and LocalSocket to create Unix domain sockets for local interprocess communication (IPC). Unix socket address can behave in three types[1],

  • pathname
  • unnamed
  • abstract

LocalServerSocket provide two public constructors for create socket in Linux abstract namespace[2] and create socket using file descriptor that's already been created and bound[3].

Create LocalServerSocket using [FileDescriptor](https://docs.oracle.com/javase/7/docs/api/j

@kraih
kraih / local_lib.txt
Created June 5, 2019 11:54
Use multiple versions of the same Perl library with local::lib
$ cpanm -Lperltidy_new Perl::Tidy
--> Working on Perl::Tidy
...
1 distribution installed
$ cpanm -Lperltidy_old Perl::Tidy@20181120
--> Working on Perl::Tidy
...
1 distribution installed