22 Şubat 2021 Pazartesi

std::is_arithmetic

Örnek
Şöyle yaparız
#include <cmath>
#include <type_traits>

template<typename T>
concept Arithmetic = std::is_arithmetic_v<T>;

template<Arithmetic T>
struct Vector2D
{
  T X = 0;
  T Y = 0;
  ...
};

15 Şubat 2021 Pazartesi

views Kütüphanesi

Giriş
std::views::filter metodu
std::views::filter metodu yazısına taşıdım

std::views::reverse
Örnek
Şöyle yaparız
#include <vector>
#include <ranges>

int main() {
  auto values = std::vector{1,2,3,4,5,6,7,8,9,10};
  auto even = [](const auto value) {
    return value % 2 == 0;
  };
  auto square = [](const auto value) {
    return value * value;
  };

  auto results1 = values
      | std::views::filter(even)
      | std::views::reverse
      | std::views::take(4)
      | std::views::reverse;

  auto results2 = values
      | std::views::transform(square)
      | std::views::reverse
      | std::views::take(4)
      | std::views::reverse;
  ...   
}

1 Şubat 2021 Pazartesi

std::is_derived_from

Giriş
Açıklaması şöyle
The concept derived_from<Derived, Base> is satisfied if and only if Base is a class type that is either Derived or a public and unambiguous base of Derived, ignoring cv-qualifiers.

Note that this behaviour is different to std::is_base_of when Base is a private or protected base of Derived.
Örnek - std::is_derived_from
Şöyle yaparız
template<std::is_derived_from<Draw_Shape> T>
class MyClass{
};