[ create a new paste ] login | about

litb

Name: Johannes Schaub
Email:
Site/Blog:
Location: Germany
Default language: C++
Favorite languages: C++, C, Java, Haskell, C#
About: I'm a nerdy dude. Be aware!

Saved pastes by litb:

C++, pasted on May 28:
1
2
3
4
5
namespace A {
template<typename T> struct a { };
}

using namespace A;
...
view (9 lines)
C++, pasted on May 26:
1
2
3
4
5
namespace isbase_detail {
template<typename T> struct identity { typedef T type; };

template<typename,typename>
struct tovoid { typedef void type; }; 
...
view (39 lines, 2 lines of output)
C++, pasted on Apr 18:
1
2
3
4
5
template <typename> struct tovoid { typedef void type; };

template <typename T, size_t KCount, typename = void>
struct ArrayStorage {
  typedef T type;
...
view (32 lines, 3 lines of output)
C++, pasted on Apr 17:
1
2
3
4
5
#include <array>
#include <cstddef>

template<typename T, std::size_t N>
struct build {
...
view (45 lines)
C++, pasted on Mar 17:
1
2
3
4
5
template<int&> struct takes_int { };

template<typename T>
struct has_int {
  static int data;
...
view (15 lines, 2 lines of output)
C++, pasted on Mar 5:
1
2
3
4
5
struct Number
{
    int num;
    Number(int n=0,int d=1) {num = n/d;}
    operator int() {return num;}
...
view (10 lines, 2 lines of output)
C++, pasted on Mar 2:
1
2
3
4
5
#include <exception>
#include <iostream>
#include <cstdlib>

// provides operators for any alignment >= 4 bytes
...
view (31 lines, 2 lines of output)
C++, pasted on Mar 1:
1
2
3
4
5
#ifndef ISBASEHPP
#define ISBASEHPP

namespace isbase_detail {
template<typename T> struct identity { typedef T type; };
...
view (37 lines)
C++, pasted on Feb 26:
1
2
3
4
5
#include <array>

template<typename T, int N>
struct build {
  template<typename ...U>
...
view (33 lines)
C++, pasted on Jan 16:
1
2
3
4
5
#include <cstddef>
#include <iostream>

namespace detail {
struct any { 
...
view (286 lines, 12 lines of output)
C++, pasted on Jan 16:
1
2
3
4
5
#include <cstddef>
#include <iostream>

namespace detail {
struct any { 
...
view (282 lines, 11 lines of output)
C++, pasted on Jan 1:
1
2
3
4
5
// Used as a container for a set of types.
template <typename... Types> struct TypePack
{
    // Given a TypePack<T1, T2, T3> and T=T4, returns TypePack<T1, T2, T3, T4>
    template <typename T>
...
view (35 lines)
C++, pasted on Dec 19:
1
2
3
4
template<typename M, typename T>
void print_offset(M *m, T * t) {
  std::cout << "this: " << (void*)t << "; member: " << (void*)m << std::endl;
}
...
view (24 lines, 5 lines of output)
C++, pasted on Oct 29:
1
2
3
4
5
namespace NS {
struct A { };
template<typename T>
struct B {
  friend void f(A) { }
...
view (14 lines, 4 lines of output)
C++, pasted on Oct 27:
1
2
3
4
5
#include <boost/mpl/assert.hpp>

template<typename T> struct not_defined : boost::mpl::false_ { }; 
template<typename T> T GetGlobal(char const *name) 
{ BOOST_MPL_ASSERT(( not_defined<T> )); }
...
view (7 lines, 4 lines of output)
C++, pasted on Oct 16:
1
2
3
4
5
namespace detail {
struct any { template<typename T> any(T const&); };
struct tag { char c[2]; };

int operator,(detail::tag, detail::tag);
...
view (63 lines, 3 lines of output)
C++, pasted on Sep 30:
1
2
3
4
5
namespace litb {
template<typename T>
struct id { typedef T type; };

// const
...
view (48 lines, 1 line of output)
C++, pasted on Sep 28:
1
2
3
4
5
#define MY_CONCAT1(D,A) D ## A
#define MY_CONCAT(D, A) MY_CONCAT1(D, A)
#define BUILD_DEDUCE(D) MY_CONCAT(DED, D)
#define DEF_DEDUCE(D) any_base const & D = make_any_concrete(BUILD_DEDUCE(D))
#define DEDUCED(D) get_t(D, true ? ded_ty() : get_idt(BUILD_DEDUCE(D)))
...
view (44 lines, 1 line of output)
C++, pasted on Sep 22:
1
2
3
4
5
#include <cstddef>
#include <algorithm>
using std::size_t;

struct Fixture {
...
view (67 lines)
C++, pasted on Sep 21:
1
2
3
4
#include <boost/bind.hpp>

struct D { template<typename T> operator T() { T t; return t; } };
template<typename T> D operator|(T, D d) { return d; } 
...
view (24 lines, 1 line of output)
C++, pasted on Sep 11:
1
2
3
4
"ComeauTest.c", line 108: error: "nelems" is not a nonstatic data member or base
          class of class "SimpleList<T>"
                  :head_(0), nelems(0)
                             ^
...
view (16 lines)
C, pasted on Aug 23:
1
2
3
4
5
void g(float a);
void f(a)
float a; {
  g(a);
}
...
view (32 lines)
C++, pasted on Aug 5:
1
2
3
4
5
struct A { };
int main() {
    int A::*p = 0;
    cout << *(ptrdiff_t*)(void*)&p << endl;
    memset(&p, 0, sizeof p);
...
view (7 lines, 2 lines of output)
C++, pasted on Jul 9:
1
2
3
4
int main() {
  void(*fp)();
  *(void**)&fp;
}
view (4 lines, 3 lines of output)
C++, pasted on Jul 8:
1
2
3
<!--

The following uses another way to tackle it. It uses a solution similar to the one found at [this thread](http://tinyurl.com/usenet-c), and linked to by @Roshan below. I took some of the ideas and wrote a version that uses a macro allowing to create a `has_to_string` template. The following is the code, each in parts. 
...
view (142 lines)
C++, pasted on Jun 28:
1
2
3
4
5
#include <boost/type_traits.hpp>
#include <utility>
#include <iostream>
#include <deque>
#include <stack>
...
view (79 lines)
C++, pasted on Jun 18:
1
2
3
4
5
#include <string>
#include <iostream>
#include <boost/function.hpp>

namespace detail {
...
view (111 lines, 10 lines of output)
C++, pasted on Jun 17:
1
2
3
4
5
#include <string>
#include <iostream>
#include <boost/function.hpp>

namespace detail {
...
view (76 lines, 6 lines of output)
C++, pasted on Jun 16:
1
2
3
4
    /* ranks */
    template<typename> struct int_rank;
    #define RANK(T, I) template<> struct int_rank<T> \
        { static int const value = I; }
...
view (103 lines, 1 line of output)
C++, pasted on Jun 15:
1
2
3
4
5
#include <boost/mpl/vector.hpp>
#include <boost/mpl/inherit_linearly.hpp>
#include <boost/mpl/inherit.hpp>
#include <boost/mpl/assert.hpp>
#include <boost/mpl/bool.hpp>
...
view (100 lines, 4 lines of output)
C++, pasted on Jun 15:
1
2
3
4
5
#include <boost/mpl/vector.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/assert.hpp>
...
view (78 lines, 4 lines of output)
C++, pasted on May 31:
1
2
3
4
    #include <iostream>
    #include <cassert>
    #include <cstdio>
    
...
view (66 lines)
C++, pasted on May 28:
1
2
3
4
5
#include <boost/mpl/vector.hpp>
#include <boost/mpl/pop_front.hpp>
#include <boost/mpl/front.hpp>
#include <boost/mpl/empty.hpp>
#include <boost/mpl/assert.hpp>
...
view (75 lines, 4 lines of output)
C, pasted on May 14:
1
2
3
4
5
int main() {
addr:
    printf("addr: %p main: %p\n", &&addr, (void*)&main);
    return 0;
}
view (5 lines, 1 line of output)
C, pasted on May 11:
1
2
3
4
; ModuleID = '<stdin>'
target datalayout = "e-p:32:32:32-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:32:64-f32:32:32-f64:32:64-v64:64:64-v128:128:128-a0:0:64-f80:32:32"
target triple = "i386-pc-linux-gnu"
@.str = internal constant [4 x i8] c"%d\0A\00"		; <[4 x i8]*> [#uses=1]
...
view (50 lines)
C++, pasted on May 7:
1
2
3
4
5
    boost::spirit::impl::concrete_parser<
        boost::spirit::alternative<
            boost::spirit::sequence<
                boost::spirit::sequence<
                    boost::spirit::sequence<
...
view (804 lines)
C++, pasted on May 7:
1
2
3
4
5
    boost::spirit::impl::concrete_parser<
        boost::spirit::alternative<
            boost::spirit::sequence<
                boost::spirit::sequence<
                    boost::spirit::sequence<
...
view (803 lines)
C++, pasted on May 7:
1
2
3
4
5
boost::spirit::impl::concrete_parser < boost::spirit::alternative <
  boost::spirit::sequence < boost::spirit::sequence <
  boost::spirit::sequence < boost::spirit::optional <
  boost::spirit::sequence < boost::spirit::inhibit_case <
  boost::spirit::contiguous < boost::spirit::sequence < boost::spirit::chseq <
...
view (728 lines)
C++, pasted on May 5:
1
2
3
4
5
#include <algorithm>
#include <boost/bind.hpp>
#include <functional>
#include <utility>
#include <vector>
...
view (26 lines)
Plain Text, pasted on Feb 2:
1
2
3
4
5
Of course, a minimal class interface is not necessarily the best interface. 
I remarked in Effective C++ that adding functions beyond those truly necessary
may be justifiable if it significantly improves the performance of the class,
makes the class easier to use, or prevents likely client errors [10]. Based on
his work with various string-like classes, Jack Reeves has observed that some 
...
view (9 lines)
C++, pasted on Jan 25:
1
2
3
4
5
#include <boost/fusion/include/sequence.hpp>
#include <boost/fusion/include/make_vector.hpp>
#include <boost/fusion/include/next.hpp>
#include <stdexcept>
#include <iostream>
...
view (76 lines)
C++, pasted on Jan 3:
1
2
3
4
5
#include <iostream>

namespace litb {
namespace detail {
// is_same
...
view (76 lines, 1 line of output)
C++, pasted on Dec 29:
1
2
3
4
5
/* fully c++03 conform (apart from long long, but which is supported by 
   major compilers). */
#include <cstdio>

/* chooses type A if cond == true, chooses type B if cond == false */
...
view (48 lines, 2 lines of output)
C++, pasted on Nov 24:
1
2
3
4
#include <iostream>
#include <fstream>
#include <cctype>
#include <sstream>
...
view (107 lines, 2 lines of output)
Plain Text, pasted on Nov 23:
1
2
3
4
5
#0  0x08048730 in main ()
#0  0x080487d5 in operator>><echot> ()
#0  0x080487ba in echot::chain<std::istream&>::chain ()
#0  0x080487b4 in transformer<echot::chain<std::istream&> >::transformer ()
#0  0x08048819 in operator>><echot::chain<std::istream&>, noiset> ()
...
view (15 lines)
Plain Text, pasted on Nov 23:
1
2
3
4
5
#0  main () at streaming.cpp:47
0
98
Current language:  auto; currently asm
#0  0x080485d8 in std::ios_base::Init::~Init ()
view (5 lines)
C++, pasted on Nov 12:
1
2
3
4
5
#include <boost/lambda/lambda.hpp>
#include <string>
#include <iostream>

using namespace boost::lambda;
...
view (14 lines, 1 line of output)
C++, pasted on Jul 14:
1
2
3
4
5
#include "turing.hpp"
#include "is_same.hpp"
#include "printer.hpp"
#include "type_list.hpp"
#include <iostream>
...
view (32 lines)
C++, pasted on Jul 14:
1
2
3
4
5
#include "turing.hpp"
#include "is_same.hpp"
#include <iostream>

template<typename T> 
...
view (31 lines)