Skip to content

Instantly share code, notes, and snippets.

View mhepeyiler's full-sized avatar
🏠
Working from home

Murat Hepeyiler mhepeyiler

🏠
Working from home
View GitHub Profile
@mhepeyiler
mhepeyiler / move_semantics_type_trait.cpp
Created February 22, 2021 15:48
Move Semantics Medium Article Type Trait
#include <iostream>
#include <type_traits>
int main()
{
  int x = 0;
  int &rx = x;
  int &&rri = 10;
  std::cout << std::boolalpha;
  std::cout << std::is_lvalue_reference_v<decltype(rx)> << '\n'; // true
  std::cout << std::is_rvalue_reference_v<decltype(rx)> << '\n'; // false
@mhepeyiler
mhepeyiler / compile_time_factorial.cpp
Last active November 13, 2020 13:43
Compile time factorial function implemenetation. It uses template specialization and variable template. Thus, it needs to be compiled above C++17.
template<unsigned long long n>
constexpr unsigned long long Factorial = n * Factorial<n - 1>;
template<>
constexpr unsigned long long Factorial<0> = 1;
int main()
{
constexpr auto fact_5 = Factorial<5>; // 120
constexpr auto fact_7 = Factorial<7>; // 5040