Skip to content

Instantly share code, notes, and snippets.

View srele96's full-sized avatar
💭
...

Srecko Kostic srele96

💭
...
  • NETCONOMY
  • Serbia, Belgrade
View GitHub Profile
struct foo {
std::string type;
std::string value;
void process(const std::string&, const std::string&);
};
struct foo {
template <typename T>
foo(T p_object) {
p_object.process("hello");
}
};
struct bar {
void process(const std::string& p_value) { std::cout << p_value << "\n"; }
};
7
helloworld
5.25
6
Add int 5
Add string hello
Add float 3.5
Process int 2
Process string world
Process float 1.5
@srele96
srele96 / random_data.cpp
Created November 30, 2023 22:27
You are given a sequence of operations to perform on a list of mixed data types. The data types can include integers, strings, and floating-point numbers. Each operation will specify the type of data it should be applied to and a specific action to perform. Your task is to process these operations efficiently using type erasure in C++.
#include <iostream>
#include <memory>
#include <vector>
class object_ {
private:
struct concept_ {
virtual void process(const std::string& p_value) = 0;
virtual void out(std::ostream& p_ostream) const = 0;
@srele96
srele96 / Observer.cpp
Created November 11, 2023 02:14
Observer, Design Pattern, C++, Implementation, Virtual Method, Inheritance
#include <algorithm>
#include <functional>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
// Problem: Stock Price Alert System
//
// Description:
@srele96
srele96 / share_config.cpp
Created November 1, 2023 23:50
C++, CRTP - Curiously Recurring Template Pattern + Attorney Pattern, Share Configuration
namespace share_config {
/**
* Do not try to understand the WHY this is the way it is. It just is.
*
* I am using CRTP and Attorney pattern because I want to use them lol.
*/
struct config {
std::function<void(const std::string&, std::ostream&)> callback_one;
@srele96
srele96 / deduce_type.cpp
Created October 30, 2023 22:11
type deduction using decltype and struct callbacks with generic types
namespace deduce_type {
namespace use_decltype {
struct result {
int value;
result() : value{1} {}
explicit result(int p_value) : value{p_value} {}
@srele96
srele96 / crtp.cpp
Created October 22, 2023 18:10
C++ Understand CRTP, Curiously Recurring Template Pattern
#include <iostream>
#include <string>
namespace curiously_recurring_template_pattern {
namespace a {
template <class T>
class base {
public:
@srele96
srele96 / code.js
Created October 10, 2023 17:08
how to use hook in class component in reactjs - https://codepen.io/Flexos96/pen/bGOzOxr?editors=1010
const { useState } = React;
// Which patterns do we use?
// React children can be utilized as a function, experiment with it
function F(props) {
console.log(props.children);
console.log(props.children(0));
console.log(props.children(0, 1));
console.log(props.children([]));
return props.children();