Skip to content

Instantly share code, notes, and snippets.

@snawaz
snawaz / decltype-with-forward.md
Created August 4, 2024 12:43
Understanding decltype(auto) and auto as return types in the presence of std::forward

Alexander Pochanin posted an [interesting C++ code snippet][linkedin] on LinkedIn. Although the snippet is already a simplified version of what he has in his codebase, I've further simplified it by removing unnecessary details so we can focus on the root cause of the issue.

Puzzle

Here is the code. Find the bug:

template <typename T>
struct wrapper_a_t {
 T _value;
// https://www.hackerrank.com/challenges/missing-numbers/problem
// this solution posted as comment on, to explain how O(n) solution is designed:
// = https://www.youtube.com/watch?v=N6r9Dh68Y3o
vector<int> missingNumbers(vector<int> arr, vector<int> brr) {
auto const base = brr.front();
int freqs[100] {0};
int actual_base = base;
for(auto const item : brr) {
@snawaz
snawaz / app_one.js
Created March 16, 2019 05:55
Jaeger headers forwarding with Isito does not work
'use strict';
const express = require('express');
// Constants
const PORT = 8080;
const HOST = '0.0.0.0';
// App
const app = express();
// Start the application
tokio::run(lazy(|| {
let addr = "127.0.0.1:0".parse().unwrap();
let listener = TcpListener::bind(&addr).unwrap();
// Create the channel that is used to communicate with the
// background task.
let (tx, rx) = mpsc::channel(1_024);
// Spawn the background task: