Cosmetic changes
[invirt/third/libt4.git] / types.h
diff --git a/types.h b/types.h
index 0241bd3..53f496d 100644 (file)
--- a/types.h
+++ b/types.h
 #define types_h
 
 #include <sys/types.h>
-
 #include <algorithm>
-using std::copy;
-using std::count_if;
-using std::find;
-using std::max;
-using std::min;
-using std::min_element;
-using std::move;
-using std::swap;
-
 #include <condition_variable>
-using cond = std::condition_variable;
-using std::cv_status;
-
 #include <chrono>
-using std::chrono::duration_cast;
-using std::chrono::microseconds;
-using std::chrono::milliseconds;
-using std::chrono::nanoseconds;
-using std::chrono::seconds;
-using std::chrono::steady_clock;
-using std::chrono::system_clock;
-using std::chrono::time_point;
-using std::chrono::time_point_cast;
-
 #include <exception>
-using std::exception;
-
 #include <fstream>
-using std::ifstream;
-using std::ofstream;
-
 #include <functional>
-// std::bind conflicts with BIND(2)
-using std::function;
-using std::placeholders::_1;
-
 #include <iomanip>
 #include <iostream>
-using std::cout;
-using std::cerr;
-using std::endl;
-using std::dec;
-using std::hex;
-using std::left;
-using std::setw;
-using std::setfill;
-using std::setprecision;
-using std::ostream;
-using std::istream;
-using std::ios;
-
 #include <limits>
-using std::numeric_limits;
-
 #include <list>
-using std::list;
-
 #include <map>
-using std::map;
-
 #include <memory>
-using std::enable_shared_from_this;
-using std::make_shared;
-using std::shared_ptr;
-using std::unique_ptr;
-using std::weak_ptr;
-
 #include <mutex>
-using std::mutex;
-using lock = std::unique_lock<std::mutex>;
-
+#include <random>
 #include <stdexcept>
-using std::runtime_error;
-
 #include <sstream>
-using std::ostringstream;
-using std::istringstream;
-
 #include <string>
+#include <thread>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+#include <vector>
+
 using std::string;
-using std::to_string;
-using std::stoi;
 
-#include <thread>
+using cond = std::condition_variable;
+using lock = std::unique_lock<std::mutex>;
 using std::thread;
-using std::call_once;
-using std::once_flag;
-namespace this_thread {
-    using namespace std::this_thread;
-}
 
-#include <tuple>
+using std::shared_ptr;
+using std::unique_ptr;
+
 using std::tuple;
-using std::get;
-using std::tie;
 
-#include <type_traits>
-using std::decay;
-using std::true_type;
-using std::false_type;
-using std::is_enum;
-using std::is_member_function_pointer;
-using std::is_same;
-using std::underlying_type;
 using std::enable_if;
-using std::remove_reference;
-using std::add_const;
-
-#include <utility>
-using std::pair;
-using std::declval;
-using std::forward;
-
-#include <vector>
-using std::vector;
+using std::false_type;
+using std::true_type;
 
 // type traits and manipulators
 
 template <class A, typename I=void> struct is_const_iterable : false_type {};
 
 template<class A> struct is_const_iterable<A,
-    decltype(declval<A &>().cbegin(), declval<A &>().cend(), void())
+    decltype(std::declval<A &>().cbegin(), std::declval<A &>().cend(), void())
 > : true_type {};
 
 template <class A, typename I=void> struct supports_emplace_back : false_type {};
 
 template<class A> struct supports_emplace_back<A,
-    decltype(declval<A &>().emplace_back(declval<typename A::value_type>()), void())
+    decltype(std::declval<A &>().emplace_back(std::declval<typename A::value_type>()), void())
 > : true_type {};
 
-template<typename E>
-using enum_type_t = typename enable_if<is_enum<E>::value, typename underlying_type<E>::type>::type;
+template<typename E> using enum_type_t = typename enable_if<
+    std::is_enum<E>::value, typename std::underlying_type<E>::type>::type;
+
 template<typename E> constexpr inline enum_type_t<E> from_enum(E e) noexcept { return (enum_type_t<E>)e; }
 template<typename E> constexpr inline E to_enum(enum_type_t<E> value) noexcept { return (E)value; }
 
+
+template <class A, typename I=void> struct is_tuple_convertible : false_type {};
+
+template<class A> struct is_tuple_convertible<A,
+    decltype(std::declval<A &>()._tuple_(), void())
+> : true_type {};
+
 // string manipulation
 
 template <class A, class B>
-ostream & operator<<(ostream & o, const pair<A,B> & d) {
+std::ostream & operator<<(std::ostream & o, const std::pair<A,B> & d) {
     return o << "<" << d.first << "," << d.second << ">";
 }
 
@@ -152,15 +80,15 @@ implode(const C & v, string delim=" ") {
     auto i=v.cbegin(), end=v.cend();
     if (i == end)
         return string();
-    ostringstream oss;
+    std::ostringstream oss;
     oss << *i++;
     while (i != end)
         oss << delim << *i++;
     return oss.str();
 }
 
-inline vector<string> explode(const string & s, string delim=" ") {
-    vector<string> out;
+inline std::vector<string> explode(const string & s, string delim=" ") {
+    std::vector<string> out;
     size_t start = 0, end = 0;
     while ((end = s.find(delim, start)) != string::npos) {
         out.push_back(s.substr(start, end - start));
@@ -171,31 +99,30 @@ inline vector<string> explode(const string & s, string delim=" ") {
 }
 
 template <class A>
-typename enable_if<is_const_iterable<A>::value && !is_same<A,string>::value, ostream>::type &
-operator<<(ostream & o, const A & a) {
+typename enable_if<
+    is_const_iterable<A>::value &&
+    !std::is_same<A,string>::value, std::ostream>::type &
+operator<<(std::ostream & o, const A & a) {
     return o << "[" << implode(a, ", ") << "]";
 }
 
-#include "verify.h"
-#include "threaded_log.h"
+#include <cstdlib>
+#define VERIFY(expr) { if (!(expr)) abort(); }
 
-// struct tuple adapter, useful for marshalling
-// used like
+// struct tuple adapter, useful for marshalling and endian swapping.  usage:
+//
 // struct foo {
 //     int a, b;
 //     MEMBERS(a, b)
 // };
 
 #define MEMBERS(...) \
-inline auto _tuple_() -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); } \
-inline auto _tuple_() const -> decltype(tie(__VA_ARGS__)) { return tie(__VA_ARGS__); }
+inline auto _tuple_() { return std::tie(__VA_ARGS__); } \
+inline auto _tuple_() const { return std::tie(__VA_ARGS__); }
 
-// struct ordering and comparison
-// used like
-// struct foo {
-//     int a, b;
-//     MEMBERS(a, b)
-// };
+// struct ordering and comparison operations; requires the use of MEMBERS.
+// usage:
+//
 // LEXICOGRAPHIC_COMPARISON(foo)
 
 #define LEXICOGRAPHIC_OPERATOR(_c_, _op_) \
@@ -206,23 +133,6 @@ LEXICOGRAPHIC_OPERATOR(_c_, <) LEXICOGRAPHIC_OPERATOR(_c_, <=) \
 LEXICOGRAPHIC_OPERATOR(_c_, >) LEXICOGRAPHIC_OPERATOR(_c_, >=) \
 LEXICOGRAPHIC_OPERATOR(_c_, ==) LEXICOGRAPHIC_OPERATOR(_c_, !=)
 
-// crucial tool for tuple indexing in variadic templates
-//
-// This implementation of tuple_indices is redistributed under the MIT
-// License as an insubstantial portion of the LLVM compiler infrastructure.
-
-template <size_t...> struct tuple_indices {};
-template <size_t S, class IntTuple, size_t E> struct make_indices_imp;
-template <size_t S, size_t... Indices, size_t E> struct make_indices_imp<S, tuple_indices<Indices...>, E> {
-    typedef typename make_indices_imp<S+1, tuple_indices<Indices..., S>, E>::type type;
-};
-template <size_t E, size_t... Indices> struct make_indices_imp<E, tuple_indices<Indices...>, E> {
-    typedef tuple_indices<Indices...> type;
-};
-template <size_t E, size_t S=0> struct make_tuple_indices {
-    typedef typename make_indices_imp<S, tuple_indices<>, E>::type type;
-};
-
 // Template parameter pack expansion is not allowed in certain contexts, but
 // brace initializers (for instance, calls to constructors of empty structs)
 // are fair game.