Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r81375 - sandbox/variadic_templates/sandbox/slim/test
From: cppljevans_at_[hidden]
Date: 2012-11-16 14:29:42


Author: cppljevans
Date: 2012-11-16 14:29:41 EST (Fri, 16 Nov 2012)
New Revision: 81375
URL: http://svn.boost.org/trac/boost/changeset/81375

Log:
add new .hpp files for refactored benchmark.treebuilder.cpp
Added:
   sandbox/variadic_templates/sandbox/slim/test/DEFAULTS.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/slim/test/RETURN_ENABLE_IF_DEFAULTS.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/slim/test/as_tuple_element.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/slim/test/make_tuple.hpp (contents, props changed)
   sandbox/variadic_templates/sandbox/slim/test/tuple.benchmark.tree_builder.cpp (contents, props changed)
Text files modified:
   sandbox/variadic_templates/sandbox/slim/test/Makefile | 27 ++-------------------------
   1 files changed, 2 insertions(+), 25 deletions(-)

Added: sandbox/variadic_templates/sandbox/slim/test/DEFAULTS.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/DEFAULTS.hpp 2012-11-16 14:29:41 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,24 @@
+#ifndef DEFAULTS_HPP_INCLUDED
+#define DEFAULTS_HPP_INCLUDED
+//ChangeLog:
+// 2012-10-27.1005CST
+// WHAT:
+// Copied following code from parts of the code in
+// https://github.com/ericniebler/home/blob/master/src/tuple/tuple.cpp
+// WHY:
+// To enable reuse in other code using #include's.
+//
+//=====================================================
+
+// For adding defaulted default, copy and move constructors, and move/copy assign.
+#define DEFAULTS(CLASS) \
+ CLASS() = default; /*required for the type to be trivial!*/ \
+ CLASS(CLASS const &) = default; /* memberwise copy */ \
+ CLASS(CLASS &&) = default; /* member-wise move */ \
+ /* These would otherwise be deleted because we */ \
+ /* declared a move constructor! */ \
+ CLASS &operator=(CLASS const &) = default; /* memberwise copy assign */ \
+ CLASS &operator=(CLASS &&) = default; /* memberwise move assign */ \
+ /**/
+
+#endif

Modified: sandbox/variadic_templates/sandbox/slim/test/Makefile
==============================================================================
--- sandbox/variadic_templates/sandbox/slim/test/Makefile (original)
+++ sandbox/variadic_templates/sandbox/slim/test/Makefile 2012-11-16 14:29:41 EST (Fri, 16 Nov 2012)
@@ -1,13 +1,9 @@
-MAIN=test
-BENCHMARK=mini
-BENCHMARK=tree_builder
+include tuple_benchmark.imk
 MAIN=tuple.benchmark.$(BENCHMARK)
-BENCHMARKRUN.which=2012-11-12_13:51:16.064572
+#MAIN=test
 #MAIN=tuple_constexpr.test
 MEASURE=time
 THISFILE=Makefile
-PYTHON=python3.1
-PYTHON=python
 
 HOW=gcc4_8_20120624
 #HOW=gcc4_8v
@@ -146,23 +142,4 @@
 echo:
         @echo "SHELL="$(SHELL)
 
-.PHONY: benchmark_domain
-benchmark_domain:
- $(PYTHON) tuple_benchmark_domain.py
-
-.PHONY: benchmark_run
-benchmark_run:
- $(PYTHON) tuple_benchmark_run.py $(BENCHMARK)
-
-.PHONY: parse
-parse:
- $(PYTHON) tuple_benchmark_parserange.py tuple.benchmark.tree_builder.guage_time@$(BENCHMARKRUN.which).txt
-
-.PHONY: tags
-tags:
- python tuple_benchmark_tags.py
-
-.PHONY: plot
-plot:
- $(PYTHON) tuple_benchmark_plot.py domain_range.pkl
 

Added: sandbox/variadic_templates/sandbox/slim/test/RETURN_ENABLE_IF_DEFAULTS.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/RETURN_ENABLE_IF_DEFAULTS.hpp 2012-11-16 14:29:41 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,26 @@
+#ifndef RETURN_ENABLE_IF_DEFAULTS_HPP_INCLUDED
+#define RETURN_ENABLE_IF_DEFAULTS_HPP_INCLUDED
+//ChangeLog:
+// 2012-10-27.1005CST
+// WHAT:
+// Copied following code from parts of the code in
+// https://github.com/ericniebler/home/blob/master/src/tuple/tuple.cpp
+// WHY:
+// To enable reuse in other code using #include's.
+//
+//=====================================================
+
+// C++11 eliminates the need for macros! Oh, wait ...
+#define RETURN(...) -> decltype(__VA_ARGS__) { return __VA_ARGS__; }
+
+namespace detail_enable_if
+{
+ extern void* enabler;//only used in ENABLE_IF macro.
+}
+
+// New-style enable_if from Matt Calabrese
+#define ENABLE_IF(...) typename std::enable_if<(__VA_ARGS__)>::type *& = detail_enable_if::enabler
+
+#include "./DEFAULTS.hpp"
+
+#endif

Added: sandbox/variadic_templates/sandbox/slim/test/as_tuple_element.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/as_tuple_element.hpp 2012-11-16 14:29:41 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,35 @@
+#ifndef AS_TUPLE_ELEMENT_HPP_INCLUDED
+#define AS_TUPLE_ELEMENT_HPP_INCLUDED
+//ChangeLog:
+// 2012-10-27.1130CST
+// WHAT:
+// Copied following code from parts of the code in
+// https://github.com/ericniebler/home/blob/master/src/tuple/tuple.cpp
+// WHY:
+// To enable reuse in other code using #include's.
+//
+///////////////////////////////////////////////////
+#include <functional>
+namespace detail
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // unrefwrap
+ template<typename T>
+ struct unrefwrap
+ {
+ typedef T type;
+ };
+
+ template<typename T>
+ struct unrefwrap<std::reference_wrapper<T> >
+ {
+ typedef T &type;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // as_tuple_element
+ template<typename T>
+ using as_tuple_element = typename unrefwrap<typename std::decay<T>::type>::type;
+
+}
+#endif

Added: sandbox/variadic_templates/sandbox/slim/test/make_tuple.hpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/make_tuple.hpp 2012-11-16 14:29:41 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,48 @@
+#ifndef MAKE_TUPLE_INCLUDE_HPP
+#define MAKE_TUPLE_INCLUDE_HPP
+#include <boost/preprocessor/stringize.hpp>
+#ifndef TUPLE_IMPL
+ #define TUPLE_IMPL bcon12_vertical
+#endif
+#include BOOST_PP_STRINGIZE(tuple_impl.TUPLE_IMPL.hpp)
+#if TUPLE_BENCH_TEMPLATED_CTOR == 1
+//Acknowlegements:
+// The following code was adapted from part of the code in:
+// https://github.com/ericniebler/home/blob/master/src/tuple/unrolled_tuple.hpp
+// and repeated here:
+// https://github.com/ericniebler/home/blob/master/src/tuple/tuple.cpp
+//
+#include <functional>
+namespace detail
+{
+ ///////////////////////////////////////////////////////////////////////////
+ // unrefwrap
+ template<typename T>
+ struct unrefwrap
+ {
+ typedef T type;
+ };
+
+ template<typename T>
+ struct unrefwrap<std::reference_wrapper<T> >
+ {
+ typedef T &type;
+ };
+
+ ///////////////////////////////////////////////////////////////////////////
+ // as_tuple_element
+ template<typename T>
+ using as_tuple_element = typename unrefwrap<typename std::decay<T>::type>::type;
+
+}//detail namespace
+
+///////////////////////////////////////////////////////////////////////////////
+// make_tuple
+ template<typename ...T>
+ tuple_bench<detail::as_tuple_element<T>...>
+make_tuple(T &&...t)
+{
+ return {t...};
+}
+#endif//TUPLE_BENCH_TEMPLATED_CTOR == 1
+#endif

Added: sandbox/variadic_templates/sandbox/slim/test/tuple.benchmark.tree_builder.cpp
==============================================================================
--- (empty file)
+++ sandbox/variadic_templates/sandbox/slim/test/tuple.benchmark.tree_builder.cpp 2012-11-16 14:29:41 EST (Fri, 16 Nov 2012)
@@ -0,0 +1,65 @@
+//ChangeLog:
+// 2012-10-25.1521 CST
+// Copied code from unrolled_tuple.cpp from:
+// https://github.com/ericniebler/home/tree/master/src/tuple
+//
+///////////////////////////////////////////////////////////////////////////////
+// unrolled_tuple.cpp
+//
+// Copyright 2012 Eric Niebler.
+// Distributed under the Boost Software License, Version 1.0. (See
+// accompanying file LICENSE_1_0.txt or copy at
+// http://www.boost.org/LICENSE_1_0.txt)
+//
+
+#include <string>
+#include <cstdio>
+#include "./make_tuple.hpp"
+#include <boost/preprocessor/repetition/enum.hpp>
+
+#ifndef TUPLE_SIZE
+#define TUPLE_SIZE 2
+#endif
+
+#ifndef TREE_DEPTH
+#define TREE_DEPTH 2
+#endif
+
+template<int I>
+struct tree_builder
+{
+ #define M0(Z, N, D) ::make_tuple(static_cast<T &&>(t), std::integral_constant<int, N>())
+ #define M1(Z, N, D) auto BOOST_PP_CAT(tmp, N) = ::get<N>(res);
+
+ template<typename T>
+ static auto make_tree(T &&t)
+ -> decltype(tree_builder<I+1>::make_tree(::make_tuple(BOOST_PP_ENUM(TUPLE_SIZE, M0, ~))))
+ {
+ auto res = tree_builder<I+1>::make_tree(::make_tuple(BOOST_PP_ENUM(TUPLE_SIZE, M0, ~)));
+ // Get each element of the tuple.
+ BOOST_PP_REPEAT(TUPLE_SIZE, M1, ~)
+ return res;
+ }
+
+ #undef M1
+ #undef M0
+};
+
+template<>
+struct tree_builder<TREE_DEPTH+1>
+{
+ template<typename T>
+ static T make_tree(T &&t)
+ {
+ return static_cast<T &&>(t);
+ }
+};
+
+int main()
+{
+ char sz[] = "hello";
+ tuple_bench<int, char(&)[6]> x = ::make_tuple(1, std::ref(sz));
+ auto y = tree_builder<1>::make_tree(::make_tuple(1, "hello", 3.14, 'a', x));
+ return 0;
+}
+


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk