http://gcc.godbolt.org/
Clang support C++17 more feature than gcc 6.9
//Clang 3.9.0 compiler option -std=c++11
#include <tuple>
using namespace std;
int test1()
{
return 99;
}
std::tuple<int,int> test()
{
return make_tuple<int>(1,2);
}
int main()
{
// const auto [s1,s2]=test(); // structured binding not working
if( const auto i=test1();i==1) { //if-init works
}
return 0;
}
Thursday, September 29, 2016
C++ 17 on Compiler Explorer
Sunday, September 25, 2016
Pool vs New Thread schedule for Rx and a C++ optimzed book
https://s3-ap-southeast-1.amazonaws.com/mylekha-ebook/IT+%26+Programming/c_c%2B%2B_c%23/Optimized-C%2B%2B.pdf NewThread is EventLoopThread inside each nested call and new on each non-nested. when subscription on background blocks more than 50ms use NewThread, otherwies use Pool Thread
macro for property definition
#define VIRTUAL_VAL_RO_PROPERTY(Access, PropertyType,PropertyName,Field) \
property PropertyType PropertyName \
{ \
virtual PropertyType __clrcall get() \
{ \
return Field; \
} \
} \
private: \
PropertyType Field; \
\
Access:
volatile, reinterpre_case, constexpr, lambda and destructuring in C++14 and 17
#include "stdafx.h"
#include <iostream>
using namespace std;
namespace {
volatile uint8_t &memory(const uint16_t loc)
{
return *reinterpret_cast<uint8_t*>(loc);
}
struct VIC_II
{
static constexpr uint16_t COLOR = 0xd020;
volatile uint8_t &border()
{
return memory(COLOR);
}
volatile uint8_t& display(const uint8_t col, const uint8_t row)
{
return memory(1024 + col + row * 40);
}
auto test()
{
return std::make_tuple<int,int,int>(1, 2, 3);
}
};
}
int main()
{
const auto le = [](uint8_t i) {cout << i << endl; };
le(3);
VIC_II vic;
vic.border() = 1;
vic.border() = 2;
memory(1024) = 'a';
vic.display(1, 2) = 'b';
// destructuring inside if does not work in VS 2015
// i.e. structured binding + if initializer
if ( auto [s1, s2, s3] = vic.test();s1==1)
{
}
return 0;
}
volatile, reinterpre_case, constexpr, lambda and destructuring in C++14 and 17
#include "stdafx.h" #includeusing namespace std; namespace { volatile uint8_t &memory(const uint16_t loc) { return *reinterpret_cast (loc); } struct VIC_II { static constexpr uint16_t COLOR = 0xd020; volatile uint8_t &border() { return memory(COLOR); } volatile uint8_t& display(const uint8_t col, const uint8_t row) { return memory(1024 + col + row * 40); } auto test() { return std::make_tuple (1, 2, 3); } }; } int main() { const auto le = [](uint8_t i) {cout << i << endl; }; le(3); VIC_II vic; vic.border() = 1; vic.border() = 2; memory(1024) = 'a'; vic.display(1, 2) = 'b'; // destructuring inside if does not work in VS 2015 if ( auto [s1, s2, s3] = vic.test();s1==1) { } return 0; }
Subscribe to:
Comments (Atom)