Skip to content

Instantly share code, notes, and snippets.

View mincongzhang's full-sized avatar
🐻

MCMCM mincongzhang

🐻
View GitHub Profile

Implement a simple shared_ptr from scratch

There is a lot to consider if we want to implement a shared_ptr from scratch, but we can break it down into basic constructors, copy sematics, move sematics and eventually destructor to make it easier.

Let's follow the following structure and see how to do it.

Basic constructors

Firstly we can just add the basic members and constructors:

@mincongzhang
mincongzhang / futures_promises_example.cpp
Last active February 17, 2023 09:11
C++ use multiple promises/futures from one thread
//https://chrizog.com/cpp-thread-synchronization
#include <chrono>
#include <future>
#include <iostream>
#include <thread>
#include <vector>
struct Packet {
int id;
};
def get_stamp_duty(price, first_time_buyer):
stamp_duty = 0
not_first_time_rate = 0.0 if first_time_buyer else 0.03
if price < 125000:
stamp_duty += price*(0+not_first_time_rate)
elif price < 250000:
stamp_duty += 125000*(0+not_first_time_rate)
stamp_duty += (price-125000)*(0.02+not_first_time_rate)
elif price < 925000:
stamp_duty += 125000*(0+not_first_time_rate)
import pandas as pd
#@register_type
class DataFrameWrapper:
#@register_method
def __init__(self):
self.m_df =\
pd.DataFrame([["day1","day2","day1","day2","day1","day2"],
["A","B","A","B","C","C"],
[100,150,200,150,100,50],
[120,160,100,180,110,80]] ).T