Showing posts with label boost. Show all posts
Showing posts with label boost. Show all posts

Nov 28, 2018

[C++][cppcon 2018] std::basic_string: for more than just text - Brian Ruth


This could be one of the most interesting/hacking videos in cppcon 2018 :-D

std::basic_string can be the container other then 'char'-ish type.
i.e int, bool, UDT etc.

And, it applies SSO on those types as well, thus we might ask, why vector
doesn't have SSO?
Well, we do have in LLVM:
SmallVector.h
or Boost's:
small_vector

And we might have 'relocatable' in C++20 iff vector contains type that meets Rule Of Zero.



Sep 22, 2016

[c++] boost optional implement

Neat implement:
boost optional.hpp


Well, still waiting.
Although the current situ is quite boring and without a bit of challenge,
pursuing for pure knowledge never stops.
I can see the future is close, excitement full-fills :-)

Aug 26, 2016

[FP] Related read/study links

Reading/learning process:
  1. C++ template, the definitive guide
  2. Modern C++ design
  3. -- Above 2 books are essential for me to understand the type system in programming language in general. --
  4. Functors, Applicatives, And Monads In Pictures
  5. Yet Another Monad Tutorial (part 2: >>= and return)
  6. Monads in C++
  7. functional-cpp
  8. PyMonad
  9. Functional Programming Patterns (NDC London 2014)
  10. Railway Oriented Programming


Used boost::mpl in SRM code base intensively; as for daily coding,
having pure function, function composition in mind as the basic design of the programs.


Resources:
Category Theory:
Category Theory for the Sciences


Monad:
--
Yet Another Monad Tutorial (part 2: >>= and return)
--
Functors, Applicatives, And Monads In Pictures
Monads Demystified
Using Monads in C++ to Solve Constraints: 1. The List Monad
Monads in C++
Haskell/Understanding monads
Monad 最简介绍
函数式编程
單子 (monad) 入門(一)
單子 (monad) 入門(二)讀取單子
Understanding_monads


Condition & restarts:
Conditions and Restarts
What's a condition system and why do you want one?
Google group discussion: A tale of restarts


FP slides:
Functional Programming Patterns (NDC London 2014)
Railway Oriented Programming


Jargon of FP:
functional-programming-jargon


Haskell:
Learn You a Haskell for Great Good!
A Fistful of Monads


FP in C++ Document:
functional-cpp


C++ FP Library:
Hana Library: Monad
https://cat.github.io/
FTL - The Functional Template Library
FC++: Functional Programming in C++


Python Library:
PyMonad


javascript:
Monads in JavaScript (7 min read)


Reddit talk:
reddit

Dec 2, 2014

[C++][boost] optional got ya.

Reference:
A gotcha with Optional

Long story short:
boost::optional has overloaded operator<
and
boost::none is considered as a unique value less than any other value of T

Aug 29, 2013

[C++][NOTE][ORIGINAL] Strong typedef

typedef does _not_ creates new type,

but sometimes, we really want _the_ same type but

with different _type_. Ok, it's a bit wordy.

Jul 17, 2013

[C++][work][NOTE][ORIGINAL] boost::fusion work around idea.

github: boost::fusion workaround

Issues mentioned

Code compiles with : -std=c++11

Online compiled:
stacked-crooked

#include <iostream>
#include <iostream>
#include <boost/bind.hpp>
#include <boost/bind/placeholders.hpp>
#include <boost/ref.hpp>
#include <boost/fusion/container/vector.hpp>
#include <boost/fusion/include/vector.hpp>
#include <boost/fusion/container/vector/vector_fwd.hpp>
#include <boost/fusion/include/vector_fwd.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/include/for_each.hpp>
 
namespace fusion = boost::fusion;
 
template<typename T>
class Base
{
protected:
   int get_result() const{
      return static_cast<const T*>(this)->a;
   }
};
 
class TYPE_1 : public Base<TYPE_1>
{
   friend class Base<TYPE_1>;
   int a{1};
public:
   using Base<TYPE_1>::get_result;
};
 
class TYPE_2 : public Base<TYPE_2>
{
   friend class Base<TYPE_2>;
   int a{2};
public:
   using Base<TYPE_2>::get_result;
};
 
class TYPE_3 : public Base<TYPE_3>
{
   friend class Base<TYPE_3>;
   int a{3};
public:
   using Base<TYPE_3>::get_result;
};
 
struct Stateful
{
   int sum_result{0};
};
 
struct Iterater
{
   template<typename T>
   void operator()(Stateful& state, const T& t) const{
      state.sum_result += t.get_result();
   }
};
 
int main(){
 
   fusion::vector<TYPE_1, TYPE_2, TYPE_3> vec{TYPE_1(), TYPE_2(), TYPE_3()};
   Stateful state;
   fusion::for_each(vec, boost::bind<void>(Iterater(), boost::ref(state), _1));
   std::cout << state.sum_result << std::endl; //print 6
 
}

Dec 6, 2012

[boost][mpl] lambda example typo

In Boost::mpl::lambda 's example, the code:
template< typename N1, typename N2 > struct int_plus
    : int_<( N1::value + N2::value )>
{
};

typedef lambda< int_plus<_1, int_<42> > >::type f1;
typedef bind< quote2<int_plus>, _1, int_<42> > f2;

typedef f1::apply<42>::type r1;
typedef f2::apply<42>::type r2;

BOOST_MPL_ASSERT_RELATION( r1::value, ==, 84 );
BOOST_MPL_ASSERT_RELATION( r2::value, ==, 84 );

should be:
template< typename N1, typename N2 > struct int_plus
    : int_<( N1::value + N2::value )>
{
};

typedef lambda< int_plus<_1, int_<42> > >::type f1;
typedef bind< quote2<int_plus>, _1, int_<42> > f2;

typedef f1::apply<int_<42> >::type r1;
typedef f2::apply<int_<42> >::type r2;

BOOST_MPL_ASSERT_RELATION( r1::value, ==, 84 );
BOOST_MPL_ASSERT_RELATION( r2::value, ==, 84 );