- 1
std::thread_fence(get_current_memory_order());Нашли или выдавили из себя код, который нельзя назвать нормальным, на который без улыбки не взглянешь? Не торопитесь его удалять или рефакторить, — запостите его на говнокод.ру, посмеёмся вместе!
Всего: 223
+14
std::thread_fence(get_current_memory_order());
+16
#include <iostream>
using namespace std;
struct T
{
  int a, b, &c;
  T():a(0), b(1), c(a){cout<<"dc"<<endl;}
  T(const T& a):a(a.a), b(a.b), c(&a.c == &a.a ? this->a : b){cout<<"cc"<<endl;}
  T& operator=(T a)
  {
    ::new((void*)(&b+1)) int*(&a.c == &a.a ? &this->a : &b);
    //asm volatile ("" : : : "memory");
    cout<<"co"<<endl;
    return *this;
  }
  void Switch()
  {
    ::new((void*)(&b+1)) int*(&c == &a ? &b : &a);
    //asm volatile ("" : : : "memory");
    cout<<"sw"<<endl;
  }
} __attribute__((aligned(1))) ;
int main() {
  T a;
  cout<<a.a<<endl;
  cout<<a.b<<endl;
  cout<<a.c<<endl;
  a.Switch();
  cout<<a.c<<endl;
  T b;
  cout<<b.c<<endl;
  b=a;
  cout<<b.c<<endl;
  b.b=666;
  cout<<b.c<<endl;
  return 0;
}Очевидно откуда это.
+18
template <typename T>
  struct canref {
    struct yes { uint8_t bytes[1]; };
    struct no  { uint8_t bytes[2]; };
    template <typename U>    static yes test(U*p);
    template <typename U>    static no  test(...);
    static const bool value = sizeof(test<T>(NULL)) == sizeof(yes);
  };
  template <typename T, int N, bool CanRef=canref<T>::value>
  class array; 
  // class for all types
  template <typename T, int N>
  class array <T,N,true>
  {
    struct Bytes
    {
      uint8_t bytes[sizeof(T)];
    };
    struct TStruct
    {
      T t;
      TStruct(T t):t(t){}
    };
    Bytes elements[N];
    int count;
    void copy_ctor (int index, const T& t)
    {
      new (&((*this)[index])) T(t);      
    }
    void copy (int index, const T& t)
    {
      (*this)[index] = t;
    }
    void dtor (int index)
    {
      (*this)[index].~T();
    }
  public:
    array () : count(0) {}
    ~array () 
    {
      resize(0);
    }
    T& operator [] (int index) 
    {
      assert (index>=0 && index<count);      
      return ((TStruct*)(&elements[index]))->t;
    }
    const T& operator [] (int index) const 
    {
      assert (index>=0 && index<count);      
      return ((TStruct*)(&elements[index]))->t;
    }
    template <int M>
    array (const array<T,M> &a)
    {
      assert(a.count<=N);
      count = a.count;
      for (int i=0; i<count; ++i)
        copyctor(i, a[i]);
    }
    template <int M>
    array& operator = (const array<T,M> &a)
    {
      if (this != &a)
      {
        if (count>a.count)
        {
          for (int i=0;       i<a.count; ++i) copy(i, a[i]);
          for (int i=a.count; i<count;   ++i) dtor(i);
          count = a.count;
        } else
        {
          assert(a.count<=N);
          int ocount = count;
          count = a.count;
          for (int i=0;      i<ocount; ++i) copy(i, a[i]);
          for (int i=ocount; i<count;  ++i) copy_ctor(i, a[i]);
        }
      }
    }
    int size() 
    {
      return count;
    }Скоро даже сратору станет очевидно откуда это.
+15
struct Point3D {
  float x,y,z;
  float& operator [] (int i) {
    switch (i) {
    case 0: return x;
    case 1: return y;
    case 2: return z;
    default: assert(false);
    }
  }
};Писал Жабапоглащенный.
+125
@ECHO OFF
VESAINF %1
PAUSE
            Фикс к программе на ассемблере с исходным кодом.
http://masm32.com/board/index.php?topic=2727.msg29659#msg29659
        
+7
auto r = [&](){
for(auto i: a)
  if(i==k)
    return f(i);
}();Однажды мне знакомый рассказывал, что во многих языках плохие грязные циклы. Мол настоящие чистые циклы должны возвращать значение. Я написал ему вот это. Он многозначительно подумал и замолчал. Через две с половиной недели он уволился.
+128
object Point2D {
  type Point2D = Object {def apply(method: Method): method.type#signature}
  trait Method {
    type signature
  }
  object ToString extends Method {
    override type signature = () => String
  }
  object GetX extends Method {
    override type signature = () => Int
  }
  object SetX extends Method {
    override type signature = (Int) => Point2D
  }
  def Point2D(x: Int, y: Int): Point2D = {
    class Dispatch {
      def apply(method: Method): method.signature = (method match {
        case ToString => () => s"($x, $y)"
        case GetX => () => x
        case SetX => (x: Int) => Point2D(x, y)
      }).asInstanceOf[method.signature]
    }
    new Dispatch
  }
}
+9
// fib.h
#pragma once
using ull = unsigned long long;
inline constexpr ull fib(size_t n, ull first, ull second) {
  return n == 0 ? first : fib(n - 1, second, first + second);
}
inline constexpr ull fib(size_t n) {
  return fib(n, 0, 1);
}
// fibs.h
#pragma once
#include "fib.h"
#include <array>
enum class fibs : ull {
#define FIB(i, val) fib##i = val,
#define COUNT(val) COUNT = val
#include "fibs.inl"
#undef COUNT
#undef FIB
};
std::array<ull, static_cast<size_t>(fibs::COUNT)> const & fibs_values() {
  static std::array<ull, static_cast<size_t>(fibs::COUNT)> values = {
#define FIB(i, val) val,
#define COUNT(val)
#include "fibs.inl"
#undef COUNT
#undef FIB
  };
  return values;
}
// main.cpp
#include "fibs.h"
#include <iostream>
int main() {
  using namespace std;
  for (auto fib : fibs_values()) {
    cout << fib << "," << endl;
  }
  return 0;
}
// fibs.inl = gen.exe > fibs.inl
// gen.cpp
#include "fib.h"
#include <iostream>
int main() {
  using namespace std;
  size_t i;
  for (i = 0; i < 94; i++) {
    cout << "FIB(" << i << ", " << fib(i) << ")" << endl;
  }
  cout << "COUNT(" << i << ")";
  return 0;
}
+13
auto write =    [&buf](future<int> size) -> future<bool>    { 
  return streamW.write(size.get(), buf).then(
    [](future<int> op){
      return op.get() > 0; });    };   
auto flse = [](future<int> op){
 return future::make_ready_future(false);};  auto copy = do_while(
    [&buf]() -> future<bool>    {
     return streamR.read(512, buf)    .then(
       [](future<int> op){ return (op.get() > 0) ? write : flse;});    });  
///////////////////////////////////////////////////////////////////////////
int cnt = 0;   
do  {  
cnt = await streamR.read(512, buf);   
if ( cnt == 0 ) break;   
cnt = await streamW.write(cnt, buf);   
} while (cnt > 0);
            Первое и второе угадайте что? Правильно, С++. В компиляторе студии и первое и второе будет. Первое уже даже есть. Ни первое ни второе  не приняли в  стандарт на сколько мне известно и надеюсь лобисты Майкрософт во главе с Саттером пойдут на ... подальше от крестов.
www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3722.pdf
        
+8
void print(int i) {printf("int: %d\n", i);}
void print(double f) {printf("double: %f\n", f);}
void print(char const * c) {printf("str: %s\n", c);}
void WTF(...) {}
template<typename... T>
void print(T ... t) 
{
  WTF((print(t), 0)...);
}
int main()
{
  print(1, "hello", 3.0);
  return 0;
}http://ideone.com/wddRC7