Serving the Quantitative Finance Community

 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

No new C++ until 2010, no concepts

November 4th, 2015, 8:16 pm

QuoteModules directly address a problem (scalability) listed as one of the three major areas where C++17 is expected to significantly improve daily experience of the working C++ programmerModules and top-down decompositions is good. It allows a *direct* mapping to C++.
Last edited by Cuchulainn on November 3rd, 2015, 11:00 pm, edited 1 time in total.
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

No new C++ until 2010, no concepts

November 4th, 2015, 8:21 pm

Here is the same prototype in C#.
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

May 2nd, 2021, 8:01 pm

Introducing Concepts -- http://accu.org/index.php/journals/2157 -- Concepts in C++11 had many false starts. Andrew Sutton show why they are a big deal now they are with us. by Andrew SuttonAn Inline-variant-visitor with C++ Concepts -- http://accu.org/index.php/journals/2160 -- Concepts are abstract. Jonathan Coe and Andrew Sutton provide us with a concrete example of their use.
Concepts and constraints in C++20 work .. I have just redesigned the Gamma GOF patterns using them. Goodbye GOF, really.
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

May 29th, 2021, 3:52 pm

// Test101Concepts.cpp
//
// Simplest example of a system. Context diagram consists only
// of Input and Output systems.
//
// We use C++20 Concepts to replace policy-based design
// 
// Composition
// 
//  V2: design using C++20 modules
// 
// (C) Datasim Education BV 2015-2021
//

#include <string>
#include <iostream>

// Interface contract specification 
template<typename T>
	concept IInput = requires (T x) { x.message(); };

template<typename T>
	concept IOutput = requires (T x, const std::string& s) { x.print(s); };

// I/O stuff
template <typename I, typename O> requires IInput<I> && IOutput<O>
	class SUD 
{ // System under discussion, using composition

private:
	I i;
	O o;
public:
	SUD(const I& input, const O& output) : i(input), o(output) {}
	void run()
	{
		o.print(i.message());
	}
};

// Instance Systems
class Input
{
public:

	std::string message() const
	{
		// Get data from hardware device
		return std::string("Good morning");
	}

};

class Output
{
public:

	void print(const std::string& s) const
	{
		std::cout << s << std::endl;
	}

};

int main()
{
	Input i; Output o;
	SUD<Input, Output> s(i,o);
	s.run();

	return 0;
}
 
User avatar
bearish
Posts: 5186
Joined: February 3rd, 2011, 2:19 pm

Re: No new C++ until 2010, no concepts

May 29th, 2021, 8:18 pm

Ah - that clears it right up! I promise to do all my PDE work in C++20 from now on.
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

June 1st, 2021, 8:53 am

Ah - that clears it right up! I promise to do all my PDE work in C++20 from now on.
A very perceptive insight! Concepts are a big deal and quant developers need to reject Rand's Objectivist Epistemology mindset that has polluted mainstream software development in the last 35 years.

the road to enlightenment

1. What are Concepts?
2. How do I use them?
3. How do I apply them? (the process )

the step 2->3 is a yuge leap of cognition, it could be a bridge too far..
"Good Heavens! For more than forty years I have been speaking prose without knowing it."

Watch this space.
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

June 14th, 2021, 8:45 am

Don't tell anyone but this is the Bridge pattern anno 2021.
// Interface contract specification 
template<typename T, typename Data>
	concept IDiffusion = requires (T c, Data t, Data x) { c.diffusion(t,x); };

template<typename T, typename Data>
	concept IDrift = requires (T c, Data t, Data x) { c.drift(t, x); };

template<typename T, typename Data>
concept IDriftDiffusion = IDiffusion<T, Data> && IDrift<T, Data>;

template <typename T, typename Data> requires IDriftDiffusion<T, Data>
		class SUD 
{ // System under discussion, using composition
  // Really a Bridge pattern

		private:
			T _t; 
		public:
		SUD(const T& t) : _t(t) {}
		Data diffusion(Data t, Data x)
		{
			return _t.diffusion(t, x);
		}
		Data drift(Data t, Data x)
		{
			return _t.drift(t, x);
		}

};
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

June 14th, 2021, 9:23 am

Ah - that clears it right up! I promise to do all my PDE work in C++20 from now on.
Have a look at the SDE/GBM model I just posted. For a PDE, just add a reaction term. Ups-a-daisy.
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

June 15th, 2021, 6:39 pm

Concepts and this (?)

A final remark on the relative merits of producing analytical solutions versus defining a finite difference framework that subsumes and supports a range of pdes sharing similar structure and functionality: in the former case each new specific option type will need its own specific formula (at great expense in human resource terms and in terms of the origination and testing of analytical option pricing formulae). Reusability of the algorithm and of code is not guaranteed and the algorithm may place restrictions on the parameters if it is to converge. Furthermore, the accuracy is fixed (and cannot be measure a priori) and it is usually not possible to customise the algorithm to suit difference performance needs. For example, it is difficult to customise the algorithm that produces six-digit accuracy to produce results to two-digit accuracy. In the latter case (using finite differences) we only need to set up a flexible software framework once and then it can be instantiated for specific types, for example spread options. A priori accuracy is determined by the mesh sizes. This usually involves nothing more than using a different payoff function with no modification of the rest of the code being needed. This is the stage in which we can apply software design patterns to achieve this desired level of flexibility. Finally, the framework can even be used for problems for which an analytical solution is not forthcoming.
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

April 6th, 2023, 12:02 pm

Bjarne Stroustrup on C++ Concepts

My (DJD) 2 cents
This is a new idea for most C++ developers. It represents a shift in thinking from the traditional OOP subtype polymorphism mindset/way of life. It is essentially functional programming and I have subsumed Concepts into my own applications (domain architectures) and teaching (www.quantnet.com). You need to take concrete cases when embarking on Concepts and realising they are essentially the same as Haskell TYPECLASSEs and are a realisation of provides-requires interfaces as seen in Module Interface Languages (MIL), which were lost in action all those years.
With co-author Harold Kasperink we have subsumed 90% of the famous GOF patterns into a Concepts framework. I have posted examples thereof on LI in the last few weeks.
Concepts are a game changer. We have been waiting on them since 2004 (Domain Architectures Duffy 2004, Wiley UK). In a word, they are "Bridge++" pattern.

https://www.youtube.com/watch?v=OPW1cDC ... LexFridman
 
User avatar
Cuchulainn
Posts: 20250
Joined: July 16th, 2004, 7:38 am
Location: 20, 000

Re: No new C++ until 2010, no concepts

April 6th, 2023, 12:04 pm

Object Oriented Programming without Inheritance - ECOOP 2015 -- Bjarne Stroustrup
of course