<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[206691] trunk/Source</title>
</head>
<body>
<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; }
#msg dl a { font-weight: bold}
#msg dl a:link { color:#fc3; }
#msg dl a:active { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.webkit.org/projects/webkit/changeset/206691">206691</a></dd>
<dt>Author</dt> <dd>weinig@apple.com</dd>
<dt>Date</dt> <dd>2016-09-30 16:10:31 -0700 (Fri, 30 Sep 2016)</dd>
</dl>
<h3>Log Message</h3>
<pre>Add initial support for IDL union conversion
https://bugs.webkit.org/show_bug.cgi?id=161576
Reviewed by Chris Dumez.
Source/WebCore:
* WebCore.xcodeproj/project.pbxproj:
Add IDLTypes.h
* bindings/generic/IDLTypes.h: Added.
Add a basic type hierarchy for types defined by WebIDL and their corresponding
WebCore implementation types.
* bindings/js/JSDOMConvert.h:
(WebCore::Converter<IDLDOMString>::convert):
(WebCore::Converter<IDLUSVString>::convert):
Add Converters for IDLDOMString and IDLUSVString.
(WebCore::ConditionalConverter<typename ReturnType, typename T, bool enabled>)
Add a struct to allow conditional conversion of types based on a compile boolean
value. This allows the union code to work, by ensuring that code for types that don't
exist doesn't get compiled.
(WebCore::Converter<IDLUnion>::convert):
Add template meta programming based version of the WebIDL conversion algorithm. It uses
introspection of the typelist to conditionally execute the parts of the algorithm that
apply and relies on the compiler eliminate the dead code it produces. This initial cut
doesn't implement the full algorithm, just a subset needed to see if this method will work
out.
* bindings/js/JSDOMWrapper.h:
(WebCore::isJSDOMWrapperType):
Add JSDOMWrapperType to the list of well known types to allow quick checking of wrappers
by the union code.
* bindings/js/JSNodeOrString.cpp:
(WebCore::toNodeOrStringVector):
Switch to new IDLUnion based converter.
Source/WTF:
* WTF.xcodeproj/project.pbxproj:
* wtf/CMakeLists.txt:
Add Brigand.h
* wtf/Brigand.h: Added.
Import a standalone copy of Edouard Alligand and Joel Falcou's
Brigand library for help with for help with list based meta programming
* wtf/StdLibExtras.h:
Add a new three new type traits, IsTemplate, IsBaseOfTemplate and RemoveCVAndReference.
- IsTemplate acts like std::is_class, but works with a generic base.
- IsBaseOfTemplate acts like std::is_base_of, but works with a generic base.
- RemoveCVAndReference combines std::remove_cv and std::remove_reference.</pre>
<h3>Modified Paths</h3>
<ul>
<li><a href="#trunkSourceWTFChangeLog">trunk/Source/WTF/ChangeLog</a></li>
<li><a href="#trunkSourceWTFWTFxcodeprojprojectpbxproj">trunk/Source/WTF/WTF.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWTFwtfCMakeListstxt">trunk/Source/WTF/wtf/CMakeLists.txt</a></li>
<li><a href="#trunkSourceWTFwtfStdLibExtrash">trunk/Source/WTF/wtf/StdLibExtras.h</a></li>
<li><a href="#trunkSourceWebCoreChangeLog">trunk/Source/WebCore/ChangeLog</a></li>
<li><a href="#trunkSourceWebCoreWebCorexcodeprojprojectpbxproj">trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMConverth">trunk/Source/WebCore/bindings/js/JSDOMConvert.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSDOMWrapperh">trunk/Source/WebCore/bindings/js/JSDOMWrapper.h</a></li>
<li><a href="#trunkSourceWebCorebindingsjsJSNodeOrStringcpp">trunk/Source/WebCore/bindings/js/JSNodeOrString.cpp</a></li>
</ul>
<h3>Added Paths</h3>
<ul>
<li><a href="#trunkSourceWTFwtfBrigandh">trunk/Source/WTF/wtf/Brigand.h</a></li>
<li><a href="#trunkSourceWebCorebindingsgenericIDLTypesh">trunk/Source/WebCore/bindings/generic/IDLTypes.h</a></li>
</ul>
</div>
<div id="patch">
<h3>Diff</h3>
<a id="trunkSourceWTFChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/ChangeLog (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/ChangeLog        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WTF/ChangeLog        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -1,3 +1,24 @@
</span><ins>+2016-09-29 Sam Weinig <sam@webkit.org>
+
+ Add initial support for IDL union conversion
+ https://bugs.webkit.org/show_bug.cgi?id=161576
+
+ Reviewed by Chris Dumez.
+
+ * WTF.xcodeproj/project.pbxproj:
+ * wtf/CMakeLists.txt:
+ Add Brigand.h
+
+ * wtf/Brigand.h: Added.
+ Import a standalone copy of Edouard Alligand and Joel Falcou's
+ Brigand library for help with for help with list based meta programming
+
+ * wtf/StdLibExtras.h:
+ Add a new three new type traits, IsTemplate, IsBaseOfTemplate and RemoveCVAndReference.
+ - IsTemplate acts like std::is_class, but works with a generic base.
+ - IsBaseOfTemplate acts like std::is_base_of, but works with a generic base.
+ - RemoveCVAndReference combines std::remove_cv and std::remove_reference.
+
</ins><span class="cx"> 2016-09-30 Filip Pizlo <fpizlo@apple.com>
</span><span class="cx">
</span><span class="cx"> B3::moveConstants should be able to edit code to minimize the number of constants
</span></span></pre></div>
<a id="trunkSourceWTFWTFxcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/WTF.xcodeproj/project.pbxproj (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WTF/WTF.xcodeproj/project.pbxproj        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -126,6 +126,7 @@
</span><span class="cx">                 70ECA60E1B02426800449739 /* SymbolImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 70ECA60B1B02426800449739 /* SymbolImpl.h */; };
</span><span class="cx">                 70ECA60F1B02426800449739 /* UniquedStringImpl.h in Headers */ = {isa = PBXBuildFile; fileRef = 70ECA60C1B02426800449739 /* UniquedStringImpl.h */; };
</span><span class="cx">                 79EC70611C99F9BC003A3AE2 /* SmallPtrSet.h in Headers */ = {isa = PBXBuildFile; fileRef = 7936D6A91C99F8AE000D1AED /* SmallPtrSet.h */; };
</span><ins>+                7C3F723A1D78811A00674E26 /* Brigand.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C3F72391D78811900674E26 /* Brigand.h */; };
</ins><span class="cx">                 7CBBA07419BB7FDC00BBF025 /* OSObjectPtr.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CBBA07319BB7FDC00BBF025 /* OSObjectPtr.h */; };
</span><span class="cx">                 7CD0D5A91D5534A7000CC9E1 /* Variant.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CD0D5A71D55322A000CC9E1 /* Variant.h */; };
</span><span class="cx">                 7CDD7FF8186D291E007433CD /* IteratorAdaptors.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */; };
</span><span class="lines">@@ -475,6 +476,7 @@
</span><span class="cx">                 70ECA60B1B02426800449739 /* SymbolImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SymbolImpl.h; sourceTree = "<group>"; };
</span><span class="cx">                 70ECA60C1B02426800449739 /* UniquedStringImpl.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = UniquedStringImpl.h; sourceTree = "<group>"; };
</span><span class="cx">                 7936D6A91C99F8AE000D1AED /* SmallPtrSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SmallPtrSet.h; sourceTree = "<group>"; };
</span><ins>+                7C3F72391D78811900674E26 /* Brigand.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Brigand.h; sourceTree = "<group>"; };
</ins><span class="cx">                 7CBBA07319BB7FDC00BBF025 /* OSObjectPtr.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = OSObjectPtr.h; sourceTree = "<group>"; };
</span><span class="cx">                 7CD0D5A71D55322A000CC9E1 /* Variant.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Variant.h; sourceTree = "<group>"; };
</span><span class="cx">                 7CDD7FF7186D291E007433CD /* IteratorAdaptors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IteratorAdaptors.h; sourceTree = "<group>"; };
</span><span class="lines">@@ -847,6 +849,7 @@
</span><span class="cx">                                 A8A47264151A825A004123FF /* BlockStack.h */,
</span><span class="cx">                                 A8A47265151A825A004123FF /* BloomFilter.h */,
</span><span class="cx">                                 0F93274A1C17F4B700CF6564 /* Box.h */,
</span><ins>+                                7C3F72391D78811900674E26 /* Brigand.h */,
</ins><span class="cx">                                 0F4570441BE834410062A629 /* BubbleSort.h */,
</span><span class="cx">                                 A8A47267151A825A004123FF /* BumpPointerAllocator.h */,
</span><span class="cx">                                 EB95E1EF161A72410089A2F5 /* ByteOrder.h */,
</span><span class="lines">@@ -1333,6 +1336,7 @@
</span><span class="cx">                                 513E170B1CD7D5BF00E3650B /* LoggingAccumulator.h in Headers */,
</span><span class="cx">                                 A8A473E6151A825B004123FF /* MainThread.h in Headers */,
</span><span class="cx">                                 1A233C7D17DAA6E300A93ACF /* MallocPtr.h in Headers */,
</span><ins>+                                7C3F723A1D78811A00674E26 /* Brigand.h in Headers */,
</ins><span class="cx">                                 A8A473E8151A825B004123FF /* MathExtras.h in Headers */,
</span><span class="cx">                                 A8A473EA151A825B004123FF /* MD5.h in Headers */,
</span><span class="cx">                                 CD5497AD15857D0300B5BC30 /* MediaTime.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWTFwtfBrigandh"></a>
<div class="addfile"><h4>Added: trunk/Source/WTF/wtf/Brigand.h (0 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/Brigand.h         (rev 0)
+++ trunk/Source/WTF/wtf/Brigand.h        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -0,0 +1,2489 @@
</span><ins>+// Brigand library
+//
+// Copyright (c) 2015 Edouard Alligand and Joel Falcou
+//
+// Boost Software License - Version 1.0 - August 17th, 2003
+//
+// Permission is hereby granted, free of charge, to any person or organization
+// obtaining a copy of the software and accompanying documentation covered by
+// this license (the "Software") to use, reproduce, display, distribute,
+// execute, and transmit the Software, and to prepare derivative works of the
+// Software, and to permit third-parties to whom the Software is furnished to
+// do so, all subject to the following:
+//
+// The copyright notices in the Software and this entire statement, including
+// the above license grant, this restriction and the following disclaimer,
+// must be included in all copies of the Software, in whole or in part, and
+// all derivative works of the Software, unless such copies or derivative
+// works are solely in the form of machine-executable object code generated by
+// a source language processor.
+//
+// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+// FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
+// SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
+// FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
+// ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+// DEALINGS IN THE SOFTWARE.
+
+// This file contains a standalone version of Edouard Alligand and Joel Falcou's
+// Brigand library, which can be found at https://github.com/edouarda/brigand
+
+#pragma once
+
+#if defined(_MSC_VER) && !defined(__GNUC__) && !defined(__clang__)
+#define BRIGAND_COMP_MSVC
+#if _MSC_VER == 1900
+#define BRIGAND_COMP_MSVC_2015
+#elif _MSC_VER == 1800
+#define BRIGAND_COMP_MSVC_2013
+#endif
+#elif __GNUC__
+#ifndef __clang__
+#define BRIGAND_COMP_GCC
+#else
+#define BRIGAND_COMP_CLANG
+#endif
+#endif
+
+#define BRIGAND_NO_BOOST_SUPPORT 1
+
+#include <cstddef>
+#include <cstdint>
+#include <cstring>
+#include <functional>
+#include <initializer_list>
+#include <tuple>
+#include <type_traits>
+#include <utility>
+
+#if !defined(BRIGAND_NO_BOOST_SUPPORT)
+#include <boost/fusion/container/vector/vector_fwd.hpp>
+#include <boost/fusion/container/deque/deque_fwd.hpp>
+#include <boost/fusion/container/list/list_fwd.hpp>
+#include <boost/fusion/container/set/set_fwd.hpp>
+#include <boost/variant.hpp>
+#endif
+
+namespace brigand
+{
+ template <class... T> struct list {};
+ template<typename T, T... Values>
+ using integral_list = brigand::list< std::integral_constant<T,Values>...>;
+ using empty_sequence = brigand::list<>;
+}
+namespace brigand
+{
+ namespace lazy
+ {
+ template <class A, template<class...> class B> struct wrap;
+ template<template<class...> class A, class... T, template<class...> class B>
+ struct wrap<A<T...>, B>
+ {
+ using type = B<T...>;
+ };
+ }
+ template<class A, template<class...> class B>
+ using wrap = typename lazy::wrap<A, B>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <typename... Ts>
+ struct append_impl
+ {
+ using type = brigand::empty_sequence;
+ };
+ template <typename T>
+ struct append_impl<T>
+ {
+ using type = T;
+ };
+ template <template <typename...> class L1, template <typename...> class L2, typename... T1s,
+ typename... T2s, typename... Ts>
+ struct append_impl<L1<T1s...>, L2<T2s...>, Ts...> : append_impl<L1<T1s..., T2s...>, Ts...>
+ {
+ };
+ template <template <typename...> class L, template <typename...> class L1,
+ template <typename...> class L2, template <typename...> class L3,
+ template <typename...> class L4, template <typename...> class L5,
+ template <typename...> class L6, template <typename...> class L7,
+ template <typename...> class L8, template <typename...> class L9,
+ template <typename...> class L10, template <typename...> class L11,
+ template <typename...> class L12, template <typename...> class L13,
+ template <typename...> class L14, template <typename...> class L15,
+ template <typename...> class L16, typename... Ts, typename... T1s, typename... T2s,
+ typename... T3s, typename... T4s, typename... T5s, typename... T6s, typename... T7s,
+ typename... T8s, typename... T9s, typename... T10s, typename... T11s,
+ typename... T12s, typename... T13s, typename... T14s, typename... T15s,
+ typename... T16s, typename... Us>
+ struct append_impl<L<Ts...>, L1<T1s...>, L2<T2s...>, L3<T3s...>, L4<T4s...>, L5<T5s...>,
+ L6<T6s...>, L7<T7s...>, L8<T8s...>, L9<T9s...>, L10<T10s...>, L11<T11s...>,
+ L12<T12s...>, L13<T13s...>, L14<T14s...>, L15<T15s...>, L16<T16s...>, Us...>
+ : append_impl<L<Ts..., T1s..., T2s..., T3s..., T4s..., T5s..., T6s..., T7s..., T8s...,
+ T9s..., T10s..., T11s..., T12s..., T13s..., T14s..., T15s..., T16s...>,
+ Us...>
+ {
+ };
+}
+namespace lazy
+{
+ template <typename... Ts>
+ using append = detail::append_impl<Ts...>;
+}
+template <typename... Ts>
+using append = typename detail::append_impl<Ts...>::type;
+namespace lazy
+{
+ template <typename T>
+ struct join;
+ template<template<typename...> class L, typename...Ts>
+ struct join<L<Ts...>> : ::brigand::detail::append_impl<L<>,Ts...>
+ {
+ };
+}
+template <typename T>
+using join = wrap<T,append>;
+}
+namespace brigand
+{
+ template <typename First, typename Second>
+ struct pair
+ {
+ using first_type = First;
+ using second_type = Second;
+ };
+}
+namespace brigand
+{
+ template<typename T> struct type_ { using type = T; };
+ template<typename T> using type_from = typename T::type;
+}
+namespace brigand
+{
+ struct no_such_type_ {};
+}
+namespace brigand
+{
+namespace lazy
+{
+ template <typename M, typename K>
+ struct lookup
+ : decltype(M::at(type_<K>{}))
+ {};
+}
+ template <typename M, typename K>
+ using lookup = typename lazy::lookup<M,K>::type;
+namespace detail
+{
+ template <class... T>
+ struct map_impl;
+ template <>
+ struct map_impl<>
+ {
+ template <typename U>
+ static type_<no_such_type_> at(U);
+ template <class K>
+ static std::false_type has_key(type_<K>);
+ template <class K>
+ static map_impl erase(type_<K>);
+ template <class P>
+ static map_impl<P> insert(type_<P>);
+ };
+ template <class... Ts>
+ struct map_impl
+ {
+ private:
+ struct Pack : pair<typename Ts::first_type, Ts>... {};
+ template<class K, class P>
+ static type_<typename P::second_type> at_impl(pair<K,P>*);
+ public:
+ template<class K>
+ static decltype(at_impl<K>(static_cast<Pack*>(nullptr))) at(type_<K>);
+ template<class K>
+ static type_<no_such_type_> at(K);
+ template <class K, class = decltype(at_impl<K>(static_cast<Pack*>(nullptr)))>
+ static std::true_type has_key(type_<K>);
+ template <class K>
+ static std::false_type has_key(K);
+ template <class K>
+ static append<map_impl<>, typename std::conditional<std::is_same<K, typename Ts::first_type>::value, list<>, list<Ts>>::type...> erase(type_<K>);
+ template <class P, class = decltype(static_cast<pair<typename P::first_type, P>*>(static_cast<Pack*>(nullptr)))>
+ static map_impl insert(type_<P>);
+ template <class P>
+ static map_impl<Ts..., typename P::type> insert(P);
+ };
+ template<class... Ts>
+ struct make_map : type_<typename Ts::first_type>... {
+ using type = map_impl<Ts...>;
+ };
+}
+ template<class... Ts>
+ using map = typename detail::make_map<Ts...>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template<class, class>
+ struct dup_append_list;
+ template<template<class...> class List, class... Ts, class... Us>
+ struct dup_append_list<List<Ts...>, List<Us...>>
+ {
+ using type = List<Ts..., Ts..., Us...>;
+ };
+ template<class T, template<class...> class List, std::size_t N>
+ struct filled_list_impl
+ : dup_append_list<
+ typename filled_list_impl<T, List, N/2>::type,
+ typename filled_list_impl<T, List, N - N/2*2>::type
+ >
+ {};
+ template<class T, template<class...> class List>
+ struct filled_list_impl<T, List, 1>
+ {
+ using type = List<T>;
+ };
+ template<class T, template<class...> class List>
+ struct filled_list_impl<T, List, 0>
+ {
+ using type = List<>;
+ };
+}
+ template<class T, std::size_t N, template<class...> class List = list>
+ using filled_list = typename detail::filled_list_impl<T, List, N>::type;
+}
+namespace brigand
+{
+ namespace detail
+ {
+ template<class T> struct element_at;
+ template<class... Ts>
+ struct element_at<list<Ts...>>
+ {
+ template<class T> type_<T> static at(Ts..., type_<T>*, ...);
+ };
+ template<std::size_t N, typename Seq> struct at_impl;
+ template<std::size_t N, template<typename...> class L, class... Ts>
+ struct at_impl<N,L<Ts...>>
+ : decltype(element_at<brigand::filled_list<void const *, N>>::at(static_cast<type_<Ts>*>(nullptr)...))
+ {
+ };
+ }
+ template <class L, std::size_t Index>
+ using at_c = typename detail::at_impl<Index, L>::type;
+namespace detail
+{
+ template <typename T>
+ struct has_at_method
+ {
+ struct dummy {};
+ template <typename C, typename P>
+ static auto test(P * p) -> decltype(C::at(*p), std::true_type());
+ template <typename, typename>
+ static std::false_type test(...);
+ static const bool value = std::is_same<std::true_type, decltype(test<T, dummy>(nullptr))>::value;
+ };
+ template <class L, typename Index, bool>
+ struct at_dispatch
+ {
+ using type = at_c<L, Index::value>;
+ };
+ template <class L, typename Index>
+ struct at_dispatch<L, Index, true>
+ {
+ using type = lookup<L, Index>;
+ };
+}
+ template <class Seq, typename K>
+ using at = typename detail::at_dispatch<Seq, K, detail::has_at_method<Seq>::value>::type;
+}
+namespace brigand
+{
+ template <template <typename...> class, typename...>
+ struct bind
+ {
+ };
+}
+namespace brigand
+{
+ template<std::size_t Index> struct args
+ {
+ };
+ struct _1 {};
+ struct _2 {};
+ using _3 = args<2>;
+ using _4 = args<3>;
+ using _5 = args<4>;
+ using _6 = args<5>;
+ using _7 = args<6>;
+ using _8 = args<7>;
+ using _9 = args<8>;
+ using _state = _1;
+ using _element = _2;
+}
+namespace brigand
+{
+template <typename T>
+struct defer
+{
+};
+template <typename T>
+struct pin
+{
+};
+template <typename T>
+struct parent
+{
+};
+namespace detail
+{
+ template <typename T, typename... Ts>
+ struct packaged_lcall
+ {
+ };
+ template <typename T, typename... Ls>
+ struct apply {
+ using type = T;
+ };
+ template <template<typename...> class F, typename...Ts, typename... Args>
+ struct apply<bind<F,Ts...>, Args...>
+ {
+ using type = F<typename apply<Ts, Args...>::type...>;
+ };
+ template <template <typename...> class F, typename... Ts, typename L, typename... Ls>
+ struct apply<F<Ts...>, L, Ls...> : F<typename apply<Ts, L, Ls...>::type...>
+ {
+ };
+ template <typename T, typename... Args, typename...Ls>
+ struct apply<pin<T>, list<Args...>, Ls...>
+ {
+ using type = T;
+ };
+ template <std::size_t N, typename L, typename...Ls>
+ struct apply<args<N>, L, Ls...>
+ {
+ using type = at_c<L, N>;
+ };
+ template <typename T, typename...Ts, typename...Ls>
+ struct apply<_1, list<T, Ts...>, Ls...>
+ {
+ using type = T;
+ };
+ template <typename T, typename U, typename...Ts, typename...Ls>
+ struct apply<_2, list<T, U, Ts...>, Ls...>
+ {
+ using type = U;
+ };
+ template <typename T, typename L, typename...Ls>
+ struct apply<parent<T>, L, Ls...> : apply<T,Ls...>
+ {
+ };
+ template <typename Lambda, typename L, typename...Ls>
+ struct apply<defer<Lambda>, L, Ls...>
+ {
+ using type = packaged_lcall<Lambda, L, Ls...>;
+ };
+ template <template <typename...> class Lambda, typename... Ts, typename... PLs, typename L, typename...Ls>
+ struct apply<packaged_lcall<Lambda<Ts...>, PLs...>, L, Ls...> : Lambda<typename apply<Ts, L, Ls..., PLs...>::type...>
+ {
+ };
+ template <template <typename...> class Lambda, typename... Ts, typename... PLs, typename L, typename...Ls>
+ struct apply<packaged_lcall<bind<Lambda,Ts...>, PLs...>, L, Ls...>
+ {
+ using type = Lambda<typename apply<Ts, L, Ls..., PLs...>::type...>;
+ };
+ template<typename T, typename...Ts>
+ using bound_apply = typename apply<T, brigand::list<Ts...>>::type;
+}
+template <typename Lambda, typename... Args>
+using apply = typename detail::apply<Lambda, brigand::list<Args...>>::type;
+}
+namespace brigand
+{
+ template<std::size_t Index> struct args;
+ namespace detail
+ {
+ template<typename T, typename List>
+ struct substitute_impl
+ {
+ using type = T;
+ };
+ template<template<class...> class T, typename... Ts, typename List>
+ struct substitute_impl<T<Ts...>,List>
+ {
+ using type = T<typename substitute_impl<Ts,List>::type...>;
+ };
+ template<std::size_t Index, typename List>
+ struct substitute_impl<args<Index>,List>
+ {
+ using type = brigand::at_c<List,Index>;
+ };
+ }
+ template<typename T, typename List>
+ using substitute = typename detail::substitute_impl<T,List>::type;
+}
+
+namespace brigand
+{
+ template <std::int8_t V>
+ using int8_t = std::integral_constant<std::int8_t, V>;
+ template <std::uint8_t V>
+ using uint8_t = std::integral_constant<std::uint8_t, V>;
+ template <std::int16_t V>
+ using int16_t = std::integral_constant<std::int16_t, V>;
+ template <std::uint16_t V>
+ using uint16_t = std::integral_constant<std::uint16_t, V>;
+ template <std::int32_t V>
+ using int32_t = std::integral_constant<std::int32_t, V>;
+ template <std::uint32_t V>
+ using uint32_t = std::integral_constant<std::uint32_t, V>;
+ template <std::int64_t V>
+ using int64_t = std::integral_constant<std::int64_t, V>;
+ template <std::uint64_t V>
+ using uint64_t = std::integral_constant<std::uint64_t, V>;
+ template<std::size_t V>
+ using size_t = std::integral_constant<std::size_t, V>;
+ template<std::ptrdiff_t V>
+ using ptrdiff_t = std::integral_constant<std::ptrdiff_t, V>;
+}
+
+namespace brigand
+{
+namespace detail
+{
+ constexpr std::size_t count_bools(bool const * const begin, bool const * const end,
+ std::size_t n)
+ {
+ return begin == end ? n : detail::count_bools(begin + 1, end, n + *begin);
+ }
+ template <bool... Bs>
+ struct template_count_bools
+ {
+ using type = ::brigand::size_t<0>;
+ };
+ template <bool B, bool... Bs>
+ struct template_count_bools<B, Bs...>
+ {
+ using type = ::brigand::size_t<B + template_count_bools<Bs...>::type::value>;
+ };
+ template <bool B1, bool B2, bool B3, bool B4, bool B5, bool B6, bool B7, bool B8, bool B9,
+ bool B10, bool B11, bool B12, bool B13, bool B14, bool B15, bool B16, bool... Bs>
+ struct template_count_bools<B1, B2, B3, B4, B5, B6, B7, B8, B9, B10, B11, B12, B13, B14, B15,
+ B16, Bs...>
+ {
+ using type =
+ ::brigand::size_t<B1 + B2 + B3 + B4 + B5 + B6 + B7 + B8 + B9 + B10 + B11 + B12 + B13 +
+ B14 + B15 + B16 + template_count_bools<Bs...>::type::value>;
+ };
+}
+namespace lazy
+{
+ template <typename List, typename Pred>
+ struct count_if
+ {
+ };
+ template <template <typename...> class S, typename Pred>
+ struct count_if<S<>, Pred>
+ {
+ using type = ::brigand::size_t<0>;
+ };
+#if defined(BRIGAND_COMP_GCC) || defined(BRIGAND_COMP_CLANG)
+ template <template <typename...> class S, template <typename...> class F>
+ struct count_if<S<>, bind<F, _1>>
+ {
+ using type = ::brigand::size_t<0>;
+ };
+ template <template <typename...> class S, template <typename...> class F>
+ struct count_if<S<>, F<_1>>
+ {
+ using type = ::brigand::size_t<0>;
+ };
+ template <template<typename...> class S, typename... Ts, typename Pred>
+ struct count_if<S<Ts...>, Pred>
+ {
+ static constexpr bool s_v[] = { ::brigand::apply<Pred, Ts>::type::value... };
+ using type = brigand::size_t<::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
+ };
+ template <template <typename...> class S, typename... Ts, template <typename...> class F>
+ struct count_if<S<Ts...>, bind<F, _1>>
+ {
+ static constexpr bool s_v[] = { F<Ts>::value... };
+ using type = brigand::size_t<::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
+ };
+ template <template <typename...> class S, typename... Ts, template <typename...> class F>
+ struct count_if<S<Ts...>, F<_1>>
+ {
+ static constexpr bool s_v[] = { F<Ts>::type::value... };
+ using type = brigand::size_t<::brigand::detail::count_bools(s_v, s_v + sizeof...(Ts), 0u)>;
+ };
+#else
+ template <template <typename...> class S, typename... Ts, typename Pred>
+ struct count_if<S<Ts...>, Pred> : ::brigand::detail::template_count_bools<::brigand::apply<Pred, Ts>::value...>
+ {
+ };
+#endif
+}
+template <typename List, typename Pred>
+using count_if = typename lazy::count_if<List, Pred>::type;
+template <class... T>
+using count = std::integral_constant<std::size_t, sizeof...(T)>;
+}
+namespace brigand
+{
+ template<class L> using size = wrap<L, count>;
+}
+namespace brigand
+{
+ namespace detail
+ {
+ template<class L, class... T> struct push_front_impl;
+ template<template<class...> class L, class... U, class... T>
+ struct push_front_impl<L<U...>, T...>
+ {
+ using type = L<T..., U...>;
+ };
+ }
+ namespace lazy {
+ template<class L, class... T>
+ struct push_front : detail::push_front_impl<L, T...>{};
+ }
+ template<class L, class... T>
+ using push_front = typename detail::push_front_impl<L, T...>::type;
+ namespace detail
+ {
+ template<class L> struct front_impl;
+ template<template<class...> class L, class T, class... U>
+ struct front_impl<L<T, U...>>
+ {
+ using type = T;
+ };
+ }
+ template <class L>
+ using front = typename detail::front_impl<L>::type;
+ namespace detail
+ {
+ template <class L, std::size_t N> struct pop_front_impl;
+ template<template<class...> class L, class T, class... U>
+ struct pop_front_impl<L<T, U...>, 1>
+ {
+ using type = L<U...>;
+ };
+ template<template<class...> class L, class> struct pop_front_element;
+ template<template<class...> class L, class... Ts>
+ struct pop_front_element<L, list<Ts...>>
+ {
+ template<class... Us>
+ static L<Us...> impl(Ts..., type_<Us>*...);
+ };
+ template<template<class...> class L, class... Ts, std::size_t N>
+ struct pop_front_impl<L<Ts...>, N>
+ {
+ using type = decltype(pop_front_element<L, filled_list<
+ void const *, N
+ >>::impl(static_cast<type_<Ts>*>(nullptr)...));
+ };
+ }
+ namespace lazy {
+ template <class L, class N = std::integral_constant<std::size_t, 1>>
+ struct pop_front : detail::pop_front_impl<L, N::value> {};
+ }
+ template <class L, class N = std::integral_constant<std::size_t, 1>>
+ using pop_front = typename detail::pop_front_impl<L, N::value>::type;
+}
+
+namespace brigand
+{
+namespace detail
+{
+ template<class L>
+ struct clear_impl;
+ template<template<class...> class L, class... Ts>
+ struct clear_impl<L<Ts...>>
+ {
+ using type = L<>;
+ };
+}
+ template<class L>
+ using clear = typename detail::clear_impl<L>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <bool b, typename O, typename L, std::size_t I>
+ struct split_at_impl;
+ template <template <typename...> class S, typename... Os, typename T, typename... Ts>
+ struct split_at_impl<false, S<Os...>, S<T, Ts...>, 0>
+ {
+ using type = S<S<Os...>, S<T, Ts...>>;
+ };
+ template <template <typename...> class S, typename... Os, typename... Ts>
+ struct split_at_impl<false, S<Os...>, S<Ts...>, 0>
+ {
+ using type = S<S<Os...>, S<Ts...>>;
+ };
+ template <template <typename...> class S, typename... Os, typename T, typename... Ts,
+ std::size_t I>
+ struct split_at_impl<false, S<Os...>, S<T, Ts...>, I>
+ : split_at_impl<false, S<Os..., T>, S<Ts...>, (I - 1)>
+ {
+ };
+ template <template <typename...> class S, typename... Os, typename T1, typename T2, typename T3,
+ typename T4, typename T5, typename T6, typename T7, typename T8, typename T9,
+ typename T10, typename T11, typename T12, typename T13, typename T14, typename T15,
+ typename T16, typename... Ts, std::size_t I>
+ struct split_at_impl<
+ true, S<Os...>,
+ S<T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, Ts...>, I>
+ : split_at_impl<((I - 16) > 16), S<Os..., T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12,
+ T13, T14, T15, T16>,
+ S<Ts...>, (I - 16)>
+ {
+ };
+ template <typename L, typename I>
+ struct call_split_at_impl : split_at_impl<(I::value > 16), brigand::clear<L>, L, I::value>
+ {
+ };
+}
+namespace lazy
+{
+ template <typename L, typename I>
+ using split_at = ::brigand::detail::call_split_at_impl<L, I>;
+}
+template <typename L, typename I>
+using split_at = typename ::brigand::lazy::split_at<L, I>::type;
+}
+namespace brigand
+{
+ namespace detail
+ {
+ template<class L, class... T> struct push_back_impl;
+ template<template<class...> class L, class... U, class... T>
+ struct push_back_impl<L<U...>, T...>
+ {
+ using type = L<U..., T...>;
+ };
+ }
+ template<class L, class... T>
+ using push_back = typename detail::push_back_impl<L, T...>::type;
+ template <class L>
+ using back = at_c<L, size<L>::value-1>;
+ template <class L, class N = std::integral_constant<std::size_t, 1>>
+ using pop_back = front<split_at<L, std::integral_constant<std::size_t, size<L>::value - N::value>>>;
+}
+namespace brigand
+{
+ namespace detail
+ {
+ template<class L1, class L2>
+ struct rot90;
+ template<
+ class... L1,
+ template<class...> class S1, class... T1,
+ template<class...> class S2, class... T2,
+ template<class...> class S3, class... T3,
+ template<class...> class S4, class... T4,
+ template<class...> class S5, class... T5,
+ template<class...> class S6, class... T6,
+ template<class...> class S7, class... T7,
+ template<class...> class S8, class... T8,
+ class... L2>
+ struct rot90<list<L1...>, list<
+ S1<T1...>, S2<T2...>, S3<T3...>, S4<T4...>,
+ S5<T5...>, S6<T6...>, S7<T7...>, S8<T8...>, L2...>>
+ : rot90<list<push_back<L1, T1, T2, T3, T4, T5, T6, T7, T8>...>, list<L2...>>
+ {};
+ template<class... L1, template<class...> class S, class... T, class... L2>
+ struct rot90<list<L1...>, list<S<T...>, L2...>>
+ : rot90<list<push_back<L1, T>...>, list<L2...>>
+ {};
+ template<class L1>
+ struct rot90<L1, list<>>
+ {
+ using type = L1;
+ };
+ template<class Func, class Seq1, class Seq2, class Seqs>
+ struct transform_impl;
+ template<class F, class T1, class T2, class Seq>
+ struct transform_apply;
+ template<class F, class T1, class T2, class... Ts>
+ struct transform_apply<F, T1, T2, list<Ts...>>
+ {
+ using type = brigand::apply<F, T1, T2, Ts...>;
+ };
+ template<
+ class Func,
+ template<class...> class Seq1, class... T1,
+ template<class...> class Seq2, class... T2,
+ class... Seqs>
+ struct transform_impl<Func, Seq1<T1...>, Seq2<T2...>, list<Seqs...>>
+ {
+ using type = Seq1<typename transform_apply<Func, T1, T2, Seqs>::type...>;
+ };
+ template<std::size_t N, class Seq1, class Seq2, class... FuncOrSeqs>
+ struct transform
+ : transform_impl<back<list<FuncOrSeqs...>>, Seq1, Seq2,
+ typename rot90<filled_list<list<>, size<Seq1>::value>, pop_back<list<FuncOrSeqs...>>>::type>
+ {};
+ template<template<class...> class Seq, class... T, class Func>
+ struct transform<0, Seq<T...>, Func>
+ {
+ using type = Seq<brigand::apply<Func, T>...>;
+ };
+ template<template<class...> class Seq, class... T, template<typename...> class Func>
+ struct transform<0, Seq<T...>, bind<Func, _1>>
+ {
+ using type = Seq<Func<T>...>;
+ };
+ template<template<class...> class Seq, class... T, template<typename...> class Func>
+ struct transform<0, Seq<T...>, Func<_1>>
+ {
+ using type = Seq<typename Func<T>::type...>;
+ };
+ template<template<class...> class Seq1, class... T1, template<class...> class Seq2, class... T2, class Func>
+ struct transform<1, Seq1<T1...>, Seq2<T2...>, Func>
+ {
+ using type = Seq1<brigand::apply<Func, T1, T2>...>;
+ };
+ }
+ namespace lazy
+ {
+ template<typename Sequence1, typename OpSeq1, typename... OpSeq2>
+ struct transform : detail::transform<sizeof...(OpSeq2), Sequence1, OpSeq1, OpSeq2...> {};
+ }
+ template<typename Sequence1, typename OpSeq1, typename... OpSeq2>
+ using transform = typename detail::transform<sizeof...(OpSeq2), Sequence1, OpSeq1, OpSeq2...>::type;
+}
+namespace brigand
+{
+ template <typename T>
+ struct make_integral : std::integral_constant <typename T::value_type, T::value> {};
+ template <typename L>
+ using as_integral_list = transform<L, make_integral<brigand::_1>>;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <typename L, template <class...> class Sequence>
+ struct as_sequence_impl
+ {
+ using type = wrap<L, Sequence>;
+ };
+}
+template <typename L, template <class...> class Sequence>
+using as_sequence = typename detail::as_sequence_impl<L, Sequence>::type;
+template <typename L>
+using as_list = as_sequence<L, brigand::list>;
+}
+namespace brigand
+{
+ template <typename... T>
+ struct pair_wrapper_
+ {
+ static_assert (sizeof...(T) == 2
+ , "as_pair requires a type list of exactly two types"
+ );
+ using type = no_such_type_;
+ };
+ template <typename T, typename U>
+ struct pair_wrapper_<T,U>
+ {
+ using type = std::pair<T,U>;
+ };
+ template <typename... T>
+ using pair_wrapper = typename pair_wrapper_<T...>::type;
+ template <typename L>
+ using as_pair = wrap<L, pair_wrapper>;
+}
+namespace brigand
+{
+ template <typename... T>
+ using tuple_wrapper = typename std::tuple<T...>;
+ template <typename L>
+ using as_tuple = wrap<L, tuple_wrapper>;
+}
+#if !defined(BRIGAND_NO_BOOST_SUPPORT)
+namespace brigand
+{
+ template <typename... T>
+ using fusion_vector_wrapper = boost::fusion::vector<T...>;
+ template <typename... T>
+ using fusion_list_wrapper = boost::fusion::list<T...>;
+ template <typename... T>
+ using fusion_deque_wrapper = boost::fusion::deque<T...>;
+ template <typename... T>
+ using fusion_set_wrapper = boost::fusion::set<T...>;
+ template <typename L> using as_fusion_vector = wrap<L, fusion_vector_wrapper>;
+ template <typename L> using as_fusion_deque = wrap<L, fusion_deque_wrapper>;
+ template <typename L> using as_fusion_list = wrap<L, fusion_list_wrapper>;
+ template <typename L> using as_fusion_set = wrap<L, fusion_set_wrapper>;
+}
+namespace brigand
+{
+ template <typename... T>
+ using variant_wrapper = typename boost::variant<T...>;
+ template <typename L>
+ using as_variant = wrap<L, variant_wrapper>;
+}
+#endif
+
+namespace brigand
+{
+ template <bool B>
+ using bool_ = std::integral_constant<bool, B>;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <typename Args>
+ struct non_null_impl : bool_<Args::value != 0>{};
+ using non_null = non_null_impl<_1>;
+}
+}
+
+namespace brigand
+{
+#ifdef BRIGAND_COMP_MSVC_2013
+ namespace detail
+ {
+ template <bool...> struct bools_ {};
+ template< typename Sequence, typename Predicate, typename... Ts> struct all_impl;
+ template< template<class...> class Sequence, typename Predicate, typename... Ts>
+ struct all_impl<Sequence<Ts...>, Predicate>
+ : std::is_same< bools_<true, ::brigand::apply<Predicate, Ts>::value...>
+ , bools_<::brigand::apply<Predicate, Ts>::value..., true>
+ >
+ {};
+ }
+#else
+ namespace detail
+ {
+ struct all_same
+ {
+ const bool value = false;
+ constexpr all_same(...) {}
+ template <typename T>
+ constexpr all_same(std::initializer_list<T *>) : value{ true }
+ {
+ }
+ };
+ template <typename Sequence, typename Predicate>
+ struct all_impl : bool_<true>{};
+ template <template <class...> class Sequence, typename Predicate, typename T, typename... Ts>
+ struct all_impl<Sequence<T,Ts...>, Predicate>
+ {
+ static constexpr all_same tester{ static_cast<::brigand::apply<Predicate, T> *>(nullptr),
+ static_cast<::brigand::apply<Predicate, Ts> *>(nullptr)... };
+ using type = bool_<(::brigand::apply<Predicate, T>::value != 0 && tester.value)>;
+ };
+ template <template <class...> class Sequence, template <typename...> class F, typename T,
+ typename... Ts>
+ struct all_impl<Sequence<T, Ts...>, bind<F, _1>>
+ {
+ static constexpr all_same tester{ static_cast<F<T> *>(nullptr),
+ static_cast<F<Ts> *>(nullptr)... };
+ using type = bool_<(F<T>::value != 0 && tester.value)>;
+ };
+ template <template <class...> class Sequence, template <typename...> class F, typename T,
+ typename... Ts>
+ struct all_impl<Sequence<T, Ts...>, F<_1>>
+ {
+ static constexpr all_same tester{ static_cast<typename F<T>::type *>(nullptr),
+ static_cast<typename F<Ts>::type *>(nullptr)... };
+ using type = bool_<(F<T>::type::value != 0 && tester.value)>;
+ };
+ }
+#endif
+ template <typename Sequence, typename Predicate = detail::non_null>
+ using all = typename detail::all_impl<Sequence, Predicate>::type;
+}
+namespace brigand
+{
+#ifdef BRIGAND_COMP_MSVC_2013
+ namespace detail
+ {
+ template<typename Sequence, typename Pred> struct none_impl
+ {
+ template<typename T>
+ struct nope
+ {
+ using that = brigand::apply<Pred, T>;
+ using type = bool_<!that::value>;
+ };
+ using type = all<Sequence, nope<_1>>;
+ };
+ }
+#else
+ namespace detail
+ {
+ template <typename Sequence, typename Predicate>
+ struct none_impl : bool_<true>{};
+ template <template <class...> class Sequence, typename Predicate, typename T, typename... Ts>
+ struct none_impl<Sequence<T,Ts...>, Predicate>
+ {
+ static constexpr all_same tester{ static_cast<::brigand::apply<Predicate, T> *>(nullptr),
+ static_cast<::brigand::apply<Predicate, Ts> *>(nullptr)... };
+ using type = bool_<(::brigand::apply<Predicate, T>::value == 0 && tester.value)>;
+ };
+ template <template <class...> class Sequence, template <typename...> class F, typename T,
+ typename... Ts>
+ struct none_impl<Sequence<T, Ts...>, bind<F, _1>>
+ {
+ static constexpr all_same tester{ static_cast<F<T> *>(nullptr),
+ static_cast<F<Ts> *>(nullptr)... };
+ using type = bool_<(F<T>::value == 0 && tester.value)>;
+ };
+ template <template <class...> class Sequence, template <typename...> class F, typename T,
+ typename... Ts>
+ struct none_impl<Sequence<T, Ts...>, F<_1>>
+ {
+ static constexpr all_same tester{ static_cast<typename F<T>::type *>(nullptr),
+ static_cast<typename F<Ts>::type *>(nullptr)... };
+ using type = bool_<(F<T>::type::value == 0 && tester.value)>;
+ };
+ }
+#endif
+ template< typename Sequence, typename Predicate = detail::non_null>
+ using none = typename detail::none_impl<Sequence,Predicate>::type;
+}
+namespace brigand
+{
+ namespace detail
+ {
+ template< typename Sequence, typename Predicate >
+ struct any_impl : bool_<!none<Sequence,Predicate>::value> {};
+ }
+ template<typename Sequence, typename Predicate = detail::non_null>
+ using any = typename detail::any_impl<Sequence,Predicate>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <template <typename...> class S, template <typename...> class F, typename... Ts>
+ struct finder
+ {
+ template <typename T>
+ using P = F<Ts..., T>;
+ template <bool InNext8, bool Match, typename... Ls>
+ struct find
+ {
+ using type = S<>;
+ };
+ template <typename L>
+ struct find<true, false, L>
+ {
+ using type = S<>;
+ };
+ template <typename L, typename... Ls>
+ struct find<true, true, L, Ls...>
+ {
+ using type = S<L, Ls...>;
+ };
+ template <typename L1, typename L2, typename... Ls>
+ struct find<true, false, L1, L2, Ls...> : find<true, F<Ts..., L2>::value, L2, Ls...>
+ {
+ };
+ template <typename L0, typename L1, typename L2, typename L3, typename L4, typename L5,
+ typename L6, typename L7, typename L8,
+ typename... Ls>
+ struct find<false, false, L0, L1, L2, L3, L4, L5, L6, L7, L8, Ls...>
+ : find<true, F<Ts..., L8>::value, L8, Ls...>
+ {
+ };
+ template <typename L1, typename L2, typename L3, typename L4, typename L5, typename L6,
+ typename L7, typename L8, typename L9, typename L10, typename L11, typename L12,
+ typename L13, typename L14, typename L15, typename L16,
+ typename... Ls>
+ struct find<false, false, L1, L2, L3, L4, L5, L6, L7, L8, L9, L10, L11, L12, L13, L14, L15,
+ L16, Ls...>
+ : find<(P<L9>::value || P<L10>::value || P<L11>::value || P<L12>::value ||
+ P<L13>::value || P<L14>::value || P<L15>::value || P<L16>::value),
+ P<L9>::value, L9, L10, L11, L12, L13, L14, L15, L16, Ls...>
+ {
+ };
+ };
+}
+}
+namespace brigand
+{
+namespace detail
+{
+ template <template<class...> class L, class...>
+ struct reverse_elements;
+ template <template <class...> class L>
+ struct reverse_elements<L>
+ {
+ using type = L<>;
+ };
+ template <template <class...> class L, class T0, class... Ts>
+ struct reverse_elements<L, T0, Ts...>
+ : append_impl<typename reverse_elements<L, Ts...>::type, L<T0>>
+ {
+ };
+ template <template <class...> class L, class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12, class T13, class T14, class T15, class... Ts>
+ struct reverse_elements<L, T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, Ts...>
+ : append_impl<typename reverse_elements<L, Ts...>::type, L<T15, T14, T13, T12, T11, T10, T9, T8, T7, T6, T5, T4, T3, T2, T1, T0>>
+ {
+ };
+ template<class L>
+ struct reverse_impl;
+ template<template<class...> class L, class... U>
+ struct reverse_impl<L<U...>>
+ : reverse_elements<L, U...>
+ {
+ };
+}
+namespace lazy
+{
+ template <typename L>
+ using reverse = typename detail::reverse_impl<L>;
+}
+ template <typename L>
+ using reverse = typename detail::reverse_impl<L>::type;
+}
+namespace brigand
+{
+namespace lazy
+{
+ template <typename Sequence, typename Predicate = ::brigand::detail::non_null>
+ struct find;
+ template <template <typename...> class Sequence, typename... Ls, typename Pred>
+ struct find<Sequence<Ls...>, Pred>
+ : detail::finder<Sequence, detail::bound_apply, Pred>::template find<
+ false, false, void, void, void, void, void, void, void, void, Ls...>
+ {
+ };
+ template <template <typename...> class Sequence, typename... Ls, template <typename...> class F>
+ struct find<Sequence<Ls...>, bind<F, _1>>
+ : detail::finder<Sequence, F>::template find<false, false, void, void, void, void, void,
+ void, void, void, Ls...>
+ {
+ };
+}
+template <typename Sequence, typename Predicate = brigand::detail::non_null>
+using find = typename lazy::find<Sequence, Predicate>::type;
+namespace lazy
+{
+ template <typename Sequence, typename Predicate = detail::non_null>
+ using reverse_find =
+ ::brigand::lazy::reverse<::brigand::find<brigand::reverse<Sequence>, Predicate>>;
+}
+template <typename Sequence, typename Predicate = detail::non_null>
+using reverse_find = typename ::brigand::lazy::reverse_find<Sequence, Predicate>::type;
+namespace detail
+{
+ template <typename Sequence, typename Predicate>
+ using find_size = size<brigand::find<Sequence, Predicate>>;
+ template <typename Sequence, typename Predicate>
+ using empty_find = bool_<find_size<Sequence, Predicate>::value == 0>;
+ template <typename Sequence, typename Predicate>
+ using non_empty_find = bool_<find_size<Sequence, Predicate>::value != 0>;
+}
+template <typename Sequence, typename Predicate = detail::non_null>
+using not_found = typename detail::empty_find<Sequence, Predicate>;
+template <typename Sequence, typename Predicate = detail::non_null>
+using found = typename detail::non_empty_find<Sequence, Predicate>;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <class L>
+ struct flatten_impl
+ {
+ using type = L;
+ };
+ template <template<class...> class L, class T>
+ struct flatten_element_impl
+ {
+ using type = L<T>;
+ };
+ template <template<class...> class L, class... Ts>
+ struct flatten_element_impl<L, L<Ts...>>
+ : append_impl<typename flatten_element_impl<L, Ts>::type...>
+ {
+ };
+ template <template<class...> class L, class... Ts>
+ struct flatten_impl<L<Ts...>>
+ : flatten_element_impl<L, L<Ts...>>
+ {
+ };
+}
+namespace lazy
+{
+ template <typename Sequence>
+ using flatten = typename detail::flatten_impl<Sequence>;
+}
+template <typename Sequence>
+using flatten = typename lazy::flatten<Sequence>::type;
+}
+namespace brigand { namespace detail
+{
+ template<class Functor, class State, class Sequence>
+ struct fold_impl
+ {
+ using type = State;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0>
+ struct fold_impl<Functor, State, Sequence<T0>>
+ {
+ using type = brigand::apply<Functor, State, T0>;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1>
+ struct fold_impl<Functor, State, Sequence<T0, T1>>
+ {
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,State, T0>, T1
+ >;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1, class T2>
+ struct fold_impl<Functor, State, Sequence<T0, T1, T2>>
+ {
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor, State, T0>, T1
+ >, T2
+ >;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1, class T2, class T3>
+ struct fold_impl<Functor, State, Sequence<T0, T1, T2, T3>>
+ {
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor, State, T0>, T1
+ >, T2
+ >, T3
+ >;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1, class T2, class T3, class T4>
+ struct fold_impl<Functor, State, Sequence<T0, T1, T2, T3, T4>>
+ {
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor, State, T0>, T1
+ >, T2
+ >, T3
+ >, T4
+ >;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1, class T2, class T3, class T4, class T5>
+ struct fold_impl<Functor, State, Sequence<T0, T1, T2, T3, T4, T5>>
+ {
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor, State, T0>, T1
+ >, T2
+ >, T3
+ >, T4
+ >, T5
+ >;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6>
+ struct fold_impl<Functor, State, Sequence<T0, T1, T2, T3, T4, T5, T6>>
+ {
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor, State, T0>, T1
+ >, T2
+ >, T3
+ >, T4
+ >, T5
+ >, T6
+ >;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7>
+ struct fold_impl<Functor, State, Sequence<T0, T1, T2, T3, T4, T5, T6, T7>>
+ {
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor, State, T0>, T1
+ >, T2
+ >, T3
+ >, T4
+ >, T5
+ >, T6
+ >, T7
+ >;
+ };
+ template<
+ class Functor, class State, template <class...> class Sequence,
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class... T>
+ struct fold_impl<Functor, State, Sequence<T0, T1, T2, T3, T4, T5, T6, T7, T...>>
+ : fold_impl<
+ Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ State, T0
+ >, T1
+ >, T2
+ >, T3
+ >, T4
+ >, T5
+ >, T6
+ >, T7
+ >,
+ Sequence<T...>
+ >
+ {};
+ template<typename Functor, typename State, typename Sequence>
+ struct reverse_fold_impl
+ {
+ using type = State;
+ };
+ template <typename Functor, typename State, template <typename...> class L, typename T, typename... Ts>
+ struct reverse_fold_impl<Functor, State, L<T, Ts...>>
+ {
+ using type =
+ brigand::apply<Functor, typename reverse_fold_impl<Functor, State, L<Ts...>>::type, T>;
+ };
+ template<
+ typename Functor, typename State, template <typename...> class L,
+ typename T0, typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename... Ts>
+ struct reverse_fold_impl<Functor, State, L<T0, T1, T2, T3, T4, T5, T6, T7, Ts...>>{
+ using type = brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ brigand::apply<Functor,
+ typename reverse_fold_impl<Functor, State, L<Ts...>>::type, T7
+ >, T6
+ >, T5
+ >, T4
+ >, T3
+ >, T2
+ >, T1
+ >, T0
+ >;
+ };
+} }
+namespace brigand
+{
+namespace lazy
+{
+ template <class Sequence, class State, class Functor>
+ using fold = typename detail::fold_impl<Functor, State, Sequence>;
+ template <class Sequence, class State, class Functor>
+ using reverse_fold = typename detail::reverse_fold_impl<Functor, State, Sequence>;
+}
+template <class Sequence, class State, class Functor>
+using fold = typename ::brigand::lazy::fold<Sequence, State, Functor>::type;
+template <class Sequence, class State, class Functor>
+using reverse_fold = typename ::brigand::lazy::reverse_fold<Sequence, State, Functor>::type;
+}
+namespace brigand
+{
+ template<class F, class...Ts> F for_each_args(F f, Ts&&...a)
+ {
+ return (void)std::initializer_list<int>{((void)std::ref(f)(static_cast<Ts&&>(a)),0)...}, f;
+ }
+}
+namespace brigand
+{
+ namespace detail
+ {
+ template<template<class...> class List, typename... Elements, typename Functor>
+ Functor for_each_impl( List<Elements...>&&, Functor f )
+ {
+ return for_each_args( f, type_<Elements>()... );
+ }
+ }
+ template<typename List, typename Functor> Functor for_each( Functor f )
+ {
+ return detail::for_each_impl( List{}, f );
+ }
+}
+namespace brigand
+{
+namespace detail
+{
+ template <bool Found, class Sequence, typename Predicate, typename NotFoundType>
+ struct index_if_impl
+ {
+ using type = ::brigand::size_t<size<Sequence>::value -
+ size<::brigand::find<Sequence, Predicate>>::value>;
+ };
+ template <class Sequence, typename Predicate, typename NotFoundType>
+ struct index_if_impl<false, Sequence, Predicate, NotFoundType>
+ {
+ using type = NotFoundType;
+ };
+}
+template <class Sequence, class Predicate, class NotFoundType = no_such_type_>
+using index_if = typename detail::index_if_impl<::brigand::found<Sequence, Predicate>::value,
+ Sequence, Predicate, NotFoundType>::type;
+template <class Sequence, typename T>
+using index_of = index_if<Sequence, std::is_same<T, ::brigand::_1>>;
+}
+
+namespace brigand
+{
+ namespace detail
+ {
+ template<class T, class, class, T>
+ struct range_cat;
+#ifdef BRIGAND_COMP_MSVC
+ template<class T, T Start, T Int>
+ struct int_plus
+ {
+ using type = std::integral_constant<T, Start + Int>;
+ };
+#endif
+ template<class T, class... Ts, T... Ints, T Start>
+ struct range_cat<T, list<Ts...>, list<std::integral_constant<T, Ints>...>, Start>
+ {
+#ifdef BRIGAND_COMP_MSVC
+ using type = list<Ts..., typename int_plus<T, Start, Ints>::type...>;
+#else
+ using type = list<Ts..., std::integral_constant<T, Start + Ints>...>;
+#endif
+ };
+ template<class T, T Start, std::size_t N>
+ struct range_impl
+ : range_cat<
+ T,
+ typename range_impl<T, Start, N/2>::type,
+ typename range_impl<T, Start, N - N/2>::type,
+ N/2
+ >
+ {};
+ template<class T, T Start>
+ struct range_impl<T, Start, 1>
+ {
+ using type = list<std::integral_constant<T, Start>>;
+ };
+ template<class T, T Start>
+ struct range_impl<T, Start, 0>
+ {
+ using type = list<>;
+ };
+ template<class T, class, class, T>
+ struct reverse_range_cat;
+#ifdef BRIGAND_COMP_MSVC
+ template<class T, T Start, T Int>
+ struct int_minus
+ {
+ using type = std::integral_constant<T, Int - Start>;
+ };
+#endif
+ template<class T, class... Ts, T... Ints, T Start>
+ struct reverse_range_cat<T, list<Ts...>, list<std::integral_constant<T, Ints>...>, Start>
+ {
+#ifdef BRIGAND_COMP_MSVC
+ using type = list<Ts..., typename int_minus<T, Start, Ints>::type...>;
+#else
+ using type = list<Ts..., std::integral_constant<T, Ints - Start>...>;
+#endif
+ };
+ template<class T, T Start, std::size_t N>
+ struct reverse_range_impl
+ : reverse_range_cat<
+ T,
+ typename reverse_range_impl<T, Start, N/2>::type,
+ typename reverse_range_impl<T, Start, N - N/2>::type,
+ N/2
+ >
+ {
+ };
+ template<class T, T Start>
+ struct reverse_range_impl<T, Start, 1>
+ {
+ using type = list<std::integral_constant<T, Start>>;
+ };
+ template<class T, T Start>
+ struct reverse_range_impl<T, Start, 0>
+ {
+ using type = list<>;
+ };
+ template <class T, T Start, T Stop>
+ struct reverse_range_safe
+ {
+ static_assert(Start >= Stop, "Invalid parameters. reverse_range<> syntax is reverse_range<type, from, down_to>");
+ using type = typename reverse_range_impl<T, Start, Start-Stop>::type;
+ };
+ }
+ template<class T, T Start, T Stop>
+ using range = typename detail::range_impl<T, Start, Stop-Start>::type;
+ template<class T, T Start, T Stop>
+ using reverse_range = typename detail::reverse_range_safe<T, Start, Stop>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template<class, class T> struct unique_x_t
+ { operator type_<T> (); };
+ template<class Ints, class... Ts>
+ struct is_set_impl;
+ template<>
+ struct is_set_impl<list<>>
+ {
+ using type = std::true_type;
+ };
+ inline std::true_type true_fn(...);
+ template<class... Ints, class... Ts>
+ struct is_set_impl<list<Ints...>, Ts...>
+ {
+ struct Pack : unique_x_t<Ints, Ts>... {};
+ template<class... Us>
+ static auto is_set(Us...) -> decltype(true_fn(static_cast<Us>(Pack())...));
+ static std::false_type is_set(...);
+ using type = decltype(is_set(type_<Ts>()...));
+ };
+}
+ template<class... Ts>
+ using is_set = typename detail::is_set_impl<range<int, 0, sizeof...(Ts)>, Ts...>::type;
+}
+
+namespace brigand
+{
+#if defined(BRIGAND_COMP_GCC) || defined(BRIGAND_COMP_CLANG)
+ namespace lazy
+ {
+ template <typename L, typename Pred>
+ struct remove_if;
+ template <template <class...> class L, typename... Ts, typename Pred>
+ struct remove_if<L<Ts...>, Pred>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<::brigand::apply<Pred, Ts>::value, list<>, list<Ts>>::type...>
+ {
+ };
+ template <template <class...> class L, typename... Ts, template<typename...> class F>
+ struct remove_if<L<Ts...>, bind<F,_1>>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<F<Ts>::value, list<>, list<Ts>>::type...>
+ {
+ };
+ template <template <class...> class L, typename... Ts, template<typename...> class F>
+ struct remove_if<L<Ts...>, F<_1>>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<F<Ts>::type::value, list<>, list<Ts>>::type...>
+ {
+ };
+ }
+ namespace lazy
+ {
+ template <typename L, typename T>
+ struct remove;
+ template <template <class...> class L, typename... Ts, typename T>
+ struct remove<L<Ts...>, T>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<std::is_same<Ts, T>::value, list<>, list<Ts>>::type...>
+ {
+ };
+ }
+ namespace lazy
+ {
+ template <typename L, typename Pred>
+ struct filter;
+ template <template <class...> class L, typename... Ts, typename Pred>
+ struct filter<L<Ts...>, Pred>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<::brigand::apply<Pred, Ts>::value, list<Ts>, list<>>::type...>
+ {
+ };
+ template <template <class...> class L, typename... Ts, template<typename...> class F>
+ struct filter<L<Ts...>, bind<F, _1>>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<F<Ts>::value, list<Ts>, list<>>::type...>
+ {
+ };
+ template <template <class...> class L, typename... Ts, template<typename...> class F>
+ struct filter<L<Ts...>, F<_1>>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<F<Ts>::type::value, list<Ts>, list<>>::type...>
+ {
+ };
+ }
+#else
+namespace detail
+{
+ template <typename Pred, typename T, bool B>
+ struct empty_if_true : std::conditional<::brigand::apply<Pred, T>::value == B, list<>, list<T>>
+ {
+ };
+ template <template <typename...> class F, typename T, bool B>
+ struct empty_if_true<bind<F, _1>, T, B> : std::conditional<F<T>::value == B, list<>, list<T>>
+ {
+ };
+ template <template <typename...> class F, typename T, bool B>
+ struct empty_if_true<F<_1>, T, B> : std::conditional<F<T>::type::value == B, list<>, list<T>>
+ {
+ };
+}
+namespace lazy
+{
+ template <typename L, typename Pred>
+ struct remove_if;
+ template <template <class...> class L, typename... Ts, typename Pred>
+ struct remove_if<L<Ts...>, Pred>
+ : ::brigand::detail::append_impl<
+ L<>, typename ::brigand::detail::empty_if_true<Pred, Ts, true>::type...>
+ {
+ };
+}
+namespace lazy
+{
+ template <typename L, typename T>
+ struct remove;
+ template <template <class...> class L, typename... Ts, typename T>
+ struct remove<L<Ts...>, T>
+ : ::brigand::detail::append_impl<
+ L<>, typename std::conditional<std::is_same<Ts, T>::value, list<>, list<Ts>>::type...>
+ {
+ };
+}
+namespace lazy
+{
+ template <typename L, typename Pred>
+ struct filter;
+ template <template <class...> class L, typename... Ts, typename Pred>
+ struct filter<L<Ts...>, Pred>
+ : ::brigand::detail::append_impl<
+ L<>, typename ::brigand::detail::empty_if_true<Pred, Ts, false>::type...>
+ {
+ };
+}
+#endif
+template <typename L, typename Pred>
+using remove_if = typename lazy::remove_if<L, Pred>::type;
+template <typename L, typename T>
+using remove = typename lazy::remove<L, T>::type;
+template <typename L, typename Pred>
+using filter = typename lazy::filter<L, Pred>::type;
+}
+namespace brigand
+{
+template <class Seq, class Pred>
+using partition = pair<filter<Seq, Pred>, remove_if<Seq, Pred>>;
+}
+
+namespace brigand
+{
+ namespace detail
+ {
+ template <typename T, typename Pred, typename NewType>
+ struct replacer : std::conditional<::brigand::apply<Pred, T>::value, NewType, T>
+ {
+ };
+ template <typename T, template <typename...> class F, typename NewType>
+ struct replacer<T, bind<F, _1>, NewType> : std::conditional<F<T>::value, NewType, T>
+ {
+ };
+ template <typename T, template <typename...> class F, typename NewType>
+ struct replacer<T, F<_1>, NewType> : std::conditional<F<T>::type::value, NewType, T>
+ {
+ };
+ }
+namespace lazy
+{
+ template <typename Sequence, typename Predicate, typename NewType>
+ struct replace_if;
+ template <template <typename...> class S, typename... Ts, typename Predicate, typename NewType>
+ struct replace_if<S<Ts...>, Predicate, NewType>
+ {
+ using type = S<typename detail::replacer<Ts, Predicate, NewType>::type...>;
+ };
+ template <typename Sequence, typename OldType, typename NewType>
+ using replace = replace_if<Sequence, std::is_same<_1, pin<OldType>>, NewType>;
+}
+template <typename Sequence, typename Predicate, typename NewType>
+using replace_if = typename ::brigand::lazy::replace_if<Sequence, Predicate, NewType>::type;
+template <typename Sequence, typename OldType, typename NewType>
+using replace = typename ::brigand::lazy::replace<Sequence, OldType, NewType>::type;
+}
+
+namespace brigand
+{
+ template<typename C, typename T, typename F>
+ inline typename std::enable_if<C::value,T&&>::type select(T&& t, F&&)
+ {
+ return std::forward<T>(t);
+ }
+ template<typename C, typename T, typename F>
+ inline typename std::enable_if<!C::value,F&&>::type select(T&&, F&& f)
+ {
+ return std::forward<F>(f);
+ }
+}
+namespace brigand
+{
+namespace detail
+{
+ template<typename TOut, typename TCurrent, typename TDelim, typename... Ts>
+ struct split_impl;
+ template<template<typename...> class L, typename... Os, typename... Cs, typename TDelim, typename T, typename... Ts>
+ struct split_impl<L<Os...>, L<Cs...>, TDelim, T, Ts...> :
+ split_impl<L<Os...>, L<Cs..., T>, TDelim, Ts...> {};
+ template<template<typename...> class L, typename... Os, typename... Cs, typename TDelim, typename T>
+ struct split_impl<L<Os...>, L<Cs...>, TDelim, T> {
+ using type = L<Os..., L<Cs..., T>>;
+ };
+ template<template<typename...> class L, typename... Os, typename... Cs, typename TDelim, typename... Ts>
+ struct split_impl<L<Os...>, L<Cs...>, TDelim, TDelim, Ts...> :
+ split_impl<L<Os..., L<Cs...>>, L<>, TDelim, Ts...> {};
+ template<template<typename...> class L, typename... Os, typename... Cs, typename TDelim>
+ struct split_impl<L<Os...>, L<Cs...>, TDelim, TDelim> {
+ using type = L<Os..., L<Cs...>>;
+ };
+ template<template<typename...> class L, typename... Os, typename TDelim, typename... Ts>
+ struct split_impl<L<Os...>, L<>, TDelim, TDelim, Ts...> :
+ split_impl<L<Os...>, L<>, TDelim, Ts...> {};
+ template<template<typename...> class L, typename... Os, typename TDelim>
+ struct split_impl<L<Os...>, L<>, TDelim, TDelim> {
+ using type = L<Os...>;
+ };
+ template<template<typename...> class L, typename... Os, typename TDelim>
+ struct split_impl<L<Os...>, L<>, TDelim> {
+ using type = L<Os...>;
+ };
+ template<typename TList, typename TDelim>
+ struct split_helper;
+ template<template<typename...> class L, typename T, typename... Ts, typename TDelim>
+ struct split_helper<L<T,Ts...>, TDelim> : split_impl<L<>, L<>, TDelim, T, Ts...>{};
+ template<template<typename...> class L, typename... T, typename TDelim>
+ struct split_helper<L<T...>, TDelim> {
+ using type = L<>;
+ };
+}
+namespace lazy
+{
+ template<typename TList, typename TDelim>
+ using split = detail::split_helper<TList, TDelim>;
+}
+template<typename TList, typename TDelim>
+using split = typename lazy::split<TList, TDelim>::type;
+}
+namespace brigand
+{
+ template <typename A, typename B>
+ struct less : bool_ < (A::value < B::value) > {};
+}
+
+namespace brigand
+{
+ namespace detail
+ {
+ template<class L, class Seq1, class Seq2, class Comp>
+ struct merge_impl;
+ template<bool, class L, class Seq1, class Seq2, class Comp>
+ struct merge_insert;
+ template<class... R, class T0, class T1, class... Ts, class U, class... Us, class Comp>
+ struct merge_insert<true, list<R...>, list<T0,T1,Ts...>, list<U,Us...>, Comp>
+ : merge_insert<::brigand::apply<Comp,T1,U>::value, list<R...,T0>, list<T1,Ts...>, list<U,Us...>, Comp>
+ {};
+ template<class... R, class T, class U, class... Us, class Comp>
+ struct merge_insert<true, list<R...>, list<T>, list<U,Us...>, Comp>
+ {
+ using list = ::brigand::list<R...,T>;
+ using left = ::brigand::list<>;
+ using right = ::brigand::list<U,Us...>;
+ };
+ template<class... R, class T, class... Ts, class U0, class U1, class... Us, class Comp>
+ struct merge_insert<false, list<R...>, list<T,Ts...>, list<U0,U1,Us...>, Comp>
+ : merge_insert<::brigand::apply<Comp,T,U1>::value, list<R...,U0>, list<T,Ts...>, list<U1,Us...>, Comp>
+ {};
+ template<class... R, class T, class... Ts, class U, class Comp>
+ struct merge_insert<false, list<R...>, list<T,Ts...>, list<U>, Comp>
+ {
+ using list = ::brigand::list<R...,U>;
+ using left = ::brigand::list<T,Ts...>;
+ using right = ::brigand::list<>;
+ };
+ template<
+ class... R,
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class... Ts,
+ class U0, class U1, class U2, class U3, class U4, class U5, class U6, class U7, class U8, class U9, class... Us, class Comp>
+ struct merge_impl<list<R...>, list<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9,Ts...>, list<U0,U1,U2,U3,U4,U5,U6,U7,U8,U9,Us...>, Comp>
+ {
+ using sub = merge_insert<::brigand::apply<Comp,T0,U0>::value, list<>, list<T0,T1,T2,T3,T4,T5,T6,T7,T8,T9>, list<U0,U1,U2,U3,U4,U5,U6,U7,U8,U9>, Comp>;
+ using type = typename merge_impl<
+ append<list<R...>, typename sub::list>,
+ append<typename sub::left, list<Ts...>>,
+ append<typename sub::right, list<Us...>>,
+ Comp
+ >::type;
+ };
+ template<class... R, class T, class... Ts, class U, class... Us, class Comp>
+ struct merge_impl<list<R...>, list<T,Ts...>, list<U,Us...>, Comp>
+ : std::conditional<
+ ::brigand::apply<Comp,T,U>::value,
+ merge_impl<list<R...,T>, list<Ts...>, list<U,Us...>, Comp>,
+ merge_impl<list<R...,U>, list<T,Ts...>, list<Us...>, Comp>
+ >::type
+ {};
+ template<class... R, class... Ts, class Comp>
+ struct merge_impl<list<R...>, list<Ts...>, list<>, Comp>
+ {
+ using type = list<R..., Ts...>;
+ };
+ template<class... R, class... Us, class Comp>
+ struct merge_impl<list<R...>, list<>, list<Us...>, Comp>
+ {
+ using type = list<R..., Us...>;
+ };
+ template<class... R, class Comp>
+ struct merge_impl<list<R...>, list<>, list<>, Comp>
+ {
+ using type = list<R...>;
+ };
+ }
+ template<class Seq1, class Seq2, class Comp = less<_1,_2>>
+ using merge = append<clear<Seq1>, typename detail::merge_impl<list<>, wrap<Seq1, list>, wrap<Seq2, list>, Comp>::type>;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <class Ls, class Seq, typename Comp>
+ struct sort_impl;
+ template<class L, class Comp>
+ struct mini_sort;
+ template<class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class... Ts, class Comp>
+ struct mini_sort<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, Ts...>, Comp>
+ : merge_impl<
+ list<>,
+ typename mini_sort<list<T0, T1, T2, T3, T4, T5, T6, T7>, Comp>::type,
+ typename mini_sort<list<T8, Ts...>, Comp>::type, Comp>
+ {};
+ template<class T0, class T1, class T2, class T3, class T4, class... Ts, class Comp>
+ struct mini_sort<list<T0, T1, T2, T3, T4, Ts...>, Comp>
+ : merge_impl<list<>, typename mini_sort<list<T0, T1, T2, T3>, Comp>::type, typename mini_sort<list<T4, Ts...>, Comp>::type, Comp>
+ {};
+ template<class T0, class T1, class T2, class T3, class Comp>
+ struct mini_sort<list<T0, T1, T2, T3>, Comp>
+ : merge_impl<list<>, typename mini_sort<list<T0, T1>, Comp>::type, typename mini_sort<list<T2, T3>, Comp>::type, Comp>
+ {};
+ template<class T0, class T1, class T2, class Comp>
+ struct mini_sort<list<T0, T1, T2>, Comp>
+ : merge_impl<list<>, typename mini_sort<list<T0, T1>, Comp>::type, list<T2>, Comp>
+ {};
+ template<class T0, class T1, class Comp>
+ struct mini_sort<list<T0, T1>, Comp>
+ {
+ using type = typename std::conditional<::brigand::apply<Comp, T0, T1>::value, list<T0, T1>, list<T1, T0>>::type;
+ };
+ template<class T0, class Comp>
+ struct mini_sort<list<T0>, Comp>
+ {
+ using type = list<T0>;
+ };
+ template <
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6,
+ class T7, class T8, class T9, class T10, class T11, class T12, class T13,
+ class T14, class T15, class T16, class T17, class... Ts, typename Comp>
+ struct sort_impl<list<>, list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Ts...>, Comp>
+ : sort_impl<
+ list<typename mini_sort<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>, Comp>::type>,
+ list<Ts...>, Comp>
+ {};
+ template <
+ class L0,
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6,
+ class T7, class T8, class T9, class T10, class T11, class T12, class T13,
+ class T14, class T15, class T16, class T17, class... Ts, typename Comp>
+ struct sort_impl<list<L0>, list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Ts...>, Comp>
+ : sort_impl<
+ list<L0, typename mini_sort<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>, Comp>::type>,
+ list<Ts...>, Comp>
+ {};
+ template <
+ class L0, class L1,
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6,
+ class T7, class T8, class T9, class T10, class T11, class T12, class T13,
+ class T14, class T15, class T16, class T17, class... Ts, typename Comp>
+ struct sort_impl<list<L0,L1>, list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Ts...>, Comp>
+ : sort_impl<
+ list<L0, L1, typename mini_sort<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>, Comp>::type>,
+ list<Ts...>, Comp>
+ {};
+ template <
+ class L0, class L1, class L2,
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6,
+ class T7, class T8, class T9, class T10, class T11, class T12, class T13,
+ class T14, class T15, class T16, class T17, class... Ts, typename Comp>
+ struct sort_impl<list<L0,L1,L2>, list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, Ts...>, Comp>
+ : sort_impl<
+ list<
+ merge<L0, L1, Comp>,
+ merge<
+ typename mini_sort<list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17>, Comp>::type, L2, Comp>>,
+ list<Ts...>, Comp>
+ {};
+ template <class T, class... Ts, typename Comp>
+ struct sort_impl<list<>, list<T, Ts...>, Comp>
+ {
+ using type = typename mini_sort<list<T, Ts...>, Comp>::type;
+ };
+ template <class L, class T, class... Ts, typename Comp>
+ struct sort_impl<list<L>, list<T, Ts...>, Comp>
+ {
+ using type = merge<typename mini_sort<list<T, Ts...>, Comp>::type, L, Comp>;
+ };
+ template <class L0, class L1, class T, class... Ts, typename Comp>
+ struct sort_impl<list<L0, L1>, list<T, Ts...>, Comp>
+ {
+ using type = merge<L0, merge<typename mini_sort<list<T, Ts...>, Comp>::type, L1, Comp>, Comp>;
+ };
+ template <class L0, class L1, class L2, class T, class... Ts, typename Comp>
+ struct sort_impl<list<L0, L1, L2>, list<T, Ts...>, Comp>
+ {
+ using type = merge<merge<L0, L1, Comp>, merge<typename mini_sort<list<T, Ts...>, Comp>::type, L2, Comp>, Comp>;
+ };
+ template <class L, typename Comp>
+ struct sort_impl<list<L>, list<>, Comp>
+ {
+ using type = L;
+ };
+ template <class L0, class L1, typename Comp>
+ struct sort_impl<list<L0, L1>, list<>, Comp>
+ {
+ using type = merge<L0,L1,Comp>;
+ };
+ template <class L0, class L1, class L2, typename Comp>
+ struct sort_impl<list<L0,L1,L2>, list<>, Comp>
+ {
+ using type = merge<merge<L0,L1,Comp>,L2,Comp>;
+ };
+ template <typename Comp>
+ struct sort_impl<list<>, list<>, Comp>
+ {
+ using type = list<>;
+ };
+ template <
+ class T0, class T1, class T2, class T3, class T4, class T5, class T6, class T7, class T8, class T9, class T10, class T11, class T12,
+ class T13, class T14, class T15, class T16, class T17, class T18, class T19, class T20, class T21, class T22, class T23, class T24,
+ class T25, class T26, class T27, class T28, class T29, class T30, class T31, class T32, class T33, class T34, class T35, class T36,
+ class T37, class T38, class T39, class T40, class T41, class T42, class T43, class T44, class T45, class T46, class T47, class T48,
+ class T49, class T50, class T51, class T52, class T53, class T54, class T55, class T56, class T57, class T58, class T59, class T60,
+ class T61, class T62, class T63, class T64, class T65, class T66, class T67, class T68, class T69, class T70, class T71, class T72,
+ class T73, class T74, class T75, class T76, class T77, class T78, class T79, class T80, class T81, class T82, class T83, class T84,
+ class T85, class T86, class T87, class T88, class T89, class T90, class T91, class T92, class T93, class T94, class T95, class T96,
+ class T97, class T98, class T99, class T100, class T101, class T102, class T103, class T104, class T105, class T106, class T107,
+ class T108, class T109, class T110, class T111, class T112, class T113, class T114, class T115, class T116, class T117, class T118,
+ class T119, class T120, class T121, class T122, class T123, class T124, class T125, class T126, class T127, class T128, class T129,
+ class T130, class T131, class T132, class T133, class T134, class T135, class T136, class T137, class T138, class T139, class T140,
+ class T141, class T142, class T143, class T144, class T145, class T146, class T147, class T148, class T149, class T150, class T151,
+ class T152, class T153, class T154, class T155, class T156, class T157, class T158, class T159, class T160, class T161, class T162,
+ class T163, class T164, class T165, class T166, class T167, class T168, class T169, class T170, class T171, class T172, class T173,
+ class T174, class T175, class T176, class T177, class T178, class T179, class T180, class T181, class T182, class T183, class T184,
+ class T185, class T186, class T187, class T188, class T189, class T190, class T191, class T192, class T193, class T194, class T195,
+ class T196, class T197, class T198, class T199, class T200, class T201, class T202, class T203, class T204, class T205, class T206,
+ class T207, class T208, class T209, class T210, class T211, class T212, class T213, class T214, class T215, class T216, class T217,
+ class T218, class T219, class T220, class T221, class T222, class T223, class T224, class T225, class T226, class T227, class T228,
+ class T229, class T230, class T231, class T232, class T233, class T234, class T235, class T236, class T237, class T238, class T239,
+ class T240, class T241, class T242, class T243, class T244, class T245, class T246, class T247, class T248, class T249, class T250,
+ class T251, class T252, class T253, class T254, class T255, typename... Ts, typename Comp>
+ struct sort_impl<list<>, list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20, T21,
+ T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45, T46, T47,
+ T48, T49, T50, T51, T52, T53, T54, T55, T56, T57, T58, T59, T60, T61, T62, T63, T64, T65, T66, T67, T68, T69, T70, T71, T72, T73,
+ T74, T75, T76, T77, T78, T79, T80, T81, T82, T83, T84, T85, T86, T87, T88, T89, T90, T91, T92, T93, T94, T95, T96, T97, T98, T99,
+ T100, T101, T102, T103, T104, T105, T106, T107, T108, T109, T110, T111, T112, T113, T114, T115, T116, T117, T118, T119, T120, T121,
+ T122, T123, T124, T125, T126, T127, T128, T129, T130, T131, T132, T133, T134, T135, T136, T137, T138, T139, T140, T141, T142, T143,
+ T144, T145, T146, T147, T148, T149, T150, T151, T152, T153, T154, T155, T156, T157, T158, T159, T160, T161, T162, T163, T164, T165,
+ T166, T167, T168, T169, T170, T171, T172, T173, T174, T175, T176, T177, T178, T179, T180, T181, T182, T183, T184, T185, T186, T187,
+ T188, T189, T190, T191, T192, T193, T194, T195, T196, T197, T198, T199, T200, T201, T202, T203, T204, T205, T206, T207, T208, T209,
+ T210, T211, T212, T213, T214, T215, T216, T217, T218, T219, T220, T221, T222, T223, T224, T225, T226, T227, T228, T229, T230, T231,
+ T232, T233, T234, T235, T236, T237, T238, T239, T240, T241, T242, T243, T244, T245, T246, T247, T248, T249, T250, T251, T252, T253,
+ T254, T255, Ts...>, Comp>
+ {
+ using type = merge<
+ typename sort_impl<list<>, list<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9, T10, T11, T12, T13, T14, T15, T16, T17, T18, T19, T20,
+ T21, T22, T23, T24, T25, T26, T27, T28, T29, T30, T31, T32, T33, T34, T35, T36, T37, T38, T39, T40, T41, T42, T43, T44, T45,
+ T46, T47, T48, T49, T50, T51, T52, T53, T54, T55, T56, T57, T58, T59, T60, T61, T62, T63, T64, T65, T66, T67, T68, T69, T70,
+ T71, T72, T73, T74, T75, T76, T77, T78, T79, T80, T81, T82, T83, T84, T85, T86, T87, T88, T89, T90, T91, T92, T93, T94, T95,
+ T96, T97, T98, T99, T100, T101, T102, T103, T104, T105, T106, T107, T108, T109, T110, T111, T112, T113, T114, T115, T116,
+ T117, T118, T119, T120, T121, T122, T123, T124, T125, T126, T127, T128, T129, T130, T131, T132, T133, T134, T135, T136, T137,
+ T138, T139, T140, T141, T142, T143, T144, T145, T146, T147, T148, T149, T150, T151, T152, T153, T154, T155, T156, T157, T158,
+ T159, T160, T161, T162, T163, T164, T165, T166, T167, T168, T169, T170, T171, T172, T173, T174, T175, T176, T177, T178, T179,
+ T180, T181, T182, T183, T184, T185, T186, T187, T188, T189, T190, T191, T192, T193, T194, T195, T196, T197, T198, T199, T200,
+ T201, T202, T203, T204, T205, T206, T207, T208, T209, T210, T211, T212, T213, T214, T215, T216, T217, T218, T219, T220, T221,
+ T222, T223, T224, T225, T226, T227, T228, T229, T230, T231, T232, T233, T234, T235, T236, T237, T238, T239, T240, T241, T242,
+ T243, T244, T245, T246, T247, T248, T249, T250, T251, T252, T253, T254>, Comp>::type,
+ typename sort_impl<list<>, list<T255, Ts...>, Comp>::type, Comp
+ >;
+ };
+}
+template <class Seq, class Comp = less<_1,_2>>
+using sort = append<clear<Seq>, typename detail::sort_impl<list<>, wrap<Seq, list>, Comp>::type>;
+}
+
+namespace brigand
+{
+ template <typename A>
+ struct complement : std::integral_constant< typename A::value_type
+ , typename A::value_type(~A::value)
+ > {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct divides : std::integral_constant < typename A::value_type, A::value / B::value > {};
+}
+namespace brigand
+{
+ template<class T>
+ struct identity
+ {
+ using type = T;
+ };
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct max : std::integral_constant < typename A::value_type
+ , (A::value < B::value) ? B::value : A::value
+ >
+ {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct min : std::integral_constant < typename A::value_type
+ , (A::value < B::value) ? A::value : B::value
+ >
+ {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct minus : std::integral_constant < typename A::value_type, A::value - B::value > {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct modulo : std::integral_constant < typename A::value_type, A::value % B::value > {};
+}
+
+namespace brigand
+{
+ template <typename A>
+ struct negate : std::integral_constant < typename A::value_type, -A::value > {};
+}
+
+namespace brigand
+{
+ template <typename A>
+ struct next : std::integral_constant < typename A::value_type, A::value + 1 > {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct plus : std::integral_constant < typename A::value_type, A::value + B::value > {};
+}
+
+namespace brigand
+{
+ template <typename A>
+ struct prev : std::integral_constant < typename A::value_type, A::value - 1 > {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct times : std::integral_constant < typename A::value_type, A::value * B::value > {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct bitand_ : std::integral_constant<typename A::value_type, A::value & B::value> {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct bitor_ : std::integral_constant<typename A::value_type, A::value | B::value> {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct bitxor_ : std::integral_constant<typename A::value_type, A::value ^ B::value> {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct shift_left : std::integral_constant<typename A::value_type, (A::value << B::value)> {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct shift_right : std::integral_constant<typename A::value_type, (A::value >> B::value)> {};
+}
+namespace brigand
+{
+ template <typename A, typename B>
+ struct equal_to : bool_ < (A::value == B::value) > {};
+}
+namespace brigand
+{
+ template <typename A, typename B>
+ struct greater : bool_<(A::value > B::value) > {};
+}
+namespace brigand
+{
+ template <typename A, typename B>
+ struct greater_equal : bool_ < (A::value >= B::value) > {};
+}
+namespace brigand
+{
+ template <typename A, typename B>
+ struct less_equal : bool_ < (A::value <= B::value) > {};
+}
+namespace brigand
+{
+ template <typename A, typename B>
+ struct not_equal_to : bool_ < (A::value != B::value) > {};
+}
+
+namespace brigand
+{
+ template <typename Condition, typename A, typename B>
+ struct eval_if
+ {
+ using type = typename std::conditional<Condition::value, A, B>::type::type;
+ };
+ template <bool Condition, typename A, typename B>
+ struct eval_if_c
+ {
+ using type = typename std::conditional<Condition, A, B>::type::type;
+ };
+}
+
+namespace brigand
+{
+ template <typename Condition, typename A, typename B>
+ struct if_ : std::conditional<Condition::value, A, B> {};
+ template <bool Condition, typename A, typename B>
+ struct if_c : std::conditional<Condition, A, B> {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct and_ : std::integral_constant <typename A::value_type, A::value && B::value > {};
+}
+
+namespace brigand
+{
+ template <typename T>
+ struct not_ : std::integral_constant<typename T::value_type, !T::value> {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct or_ : std::integral_constant < typename A::value_type, A::value || B::value > {};
+}
+
+namespace brigand
+{
+ template <typename A, typename B>
+ struct xor_ : std::integral_constant<typename A::value_type, A::value != B::value> {};
+}
+namespace brigand
+{
+ template<class T>
+ struct always
+ {
+ using type = T;
+ };
+}
+namespace brigand
+{
+namespace detail
+{
+ template<template<class> class F, unsigned N, class T>
+ struct repeat_impl
+ : repeat_impl<F, N-7, F<F<F<F<F<F<F<T>>>>>>>>
+ {};
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 7, T>
+ {
+ using type = F<F<F<F<F<F<F<T>>>>>>>;
+ };
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 6, T>
+ {
+ using type = F<F<F<F<F<F<T>>>>>>;
+ };
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 5, T>
+ {
+ using type = F<F<F<F<F<T>>>>>;
+ };
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 4, T>
+ {
+ using type = F<F<F<F<T>>>>;
+ };
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 3, T>
+ {
+ using type = F<F<F<T>>>;
+ };
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 2, T>
+ {
+ using type = F<F<T>>;
+ };
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 1, T>
+ {
+ using type = F<T>;
+ };
+ template<template<class> class F, class T>
+ struct repeat_impl<F, 0, T>
+ {
+ using type = T;
+ };
+}
+namespace lazy
+{
+ template<template<class> class F, class N, class T>
+ using repeat = typename detail::repeat_impl<F, N::value, T>;
+}
+ template<template<class> class F, class N, class T>
+ using repeat = typename ::brigand::lazy::repeat<F, N, T>::type;
+}
+
+namespace brigand
+{
+ template<typename T>
+ struct sizeof_ : std::integral_constant <std::size_t, sizeof(T)> {};
+}
+namespace brigand
+{
+namespace detail
+{
+ template<class C, class K>
+ struct has_key_impl
+ {
+ using type = decltype(C::has_key(type_<K>{}));
+ };
+}
+ template<class L, class K>
+ using has_key = typename detail::has_key_impl<L, K>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template<class Start, unsigned N, class Next, class... E>
+ struct mksq8
+ : mksq8<brigand::apply<Next, Start>, N-1, Next, E..., Start>
+ {};
+ template<class Start, class Next, class... E>
+ struct mksq8<Start, 0, Next, E...>
+ {
+ using type = list<E...>;
+ };
+ template<class Start, class Next, class... E>
+ struct mksq8<Start, 1, Next, E...>
+ {
+ using type = list<E..., Start>;
+ };
+ template<class Start, class Next>
+ struct mksq8<Start, 8, Next>
+ {
+ using t1 = brigand::apply<Next, Start>;
+ using t2 = brigand::apply<Next, t1>;
+ using t3 = brigand::apply<Next, t2>;
+ using t4 = brigand::apply<Next, t3>;
+ using t5 = brigand::apply<Next, t4>;
+ using t6 = brigand::apply<Next, t5>;
+ using t7 = brigand::apply<Next, t6>;
+ using type = list<Start, t1, t2, t3, t4, t5, t6, t7>;
+ };
+ template<template<class...> class List, class Start, unsigned N, class Next, bool, class... L>
+ struct make_sequence_impl
+ : make_sequence_impl<
+ List,
+ brigand::apply<Next, typename mksq8<Start, 8, Next>::t7>,
+ N-8,
+ Next,
+ (N-8<=8),
+ L...,
+ typename mksq8<Start, 8, Next>::type
+ >
+ {};
+ template<template<class...> class List, class Start, unsigned N, class Next, class... L>
+ struct make_sequence_impl<List, Start, N, Next, true, L...>
+ {
+ using type = append<List<>, L..., typename mksq8<Start, N, Next>::type>;
+ };
+}
+ template<class Start, unsigned N, class Next = next<_1>, template<class...> class List = list>
+ using make_sequence = typename detail::make_sequence_impl<List, Start, N, Next, (N<=8)>::type;
+}
+
+namespace brigand
+{
+ template<class L, std::size_t Index>
+ using erase_c = append<
+ front<split_at<L, size_t<Index>>>,
+ pop_front<back<split_at<L, size_t<Index>>>>
+ >;
+namespace detail
+{
+ template <typename T>
+ struct has_erase_method
+ {
+ struct dummy {};
+ template <typename C, typename P>
+ static auto test(P * p) -> decltype(C::erase(type_<P>{}), std::true_type());
+ template <typename, typename>
+ static std::false_type test(...);
+ static const bool value = std::is_same<std::true_type, decltype(test<T, dummy>(nullptr))>::value;
+ };
+ template<class L, class I, bool>
+ struct erase_dispatch
+ {
+ using type = erase_c<L, I::value>;
+ };
+ template<class C, class K>
+ struct erase_dispatch<C, K, true>
+ {
+ using type = decltype(C::erase(type_<K>{}));
+ };
+}
+ template<class L, class K>
+ using erase = typename detail::erase_dispatch<L, K, detail::has_erase_method<L>::value>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <class C, class T>
+ struct insert_impl
+ {
+ using type = decltype(C::insert(type_<T>{}));
+ };
+}
+ template<class L, class T>
+ using insert = typename detail::insert_impl<L, T>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <class L, class K>
+ struct contains_impl
+ {
+ using type = decltype(L::contains(type_<K>{}));
+ };
+}
+ template <class L, class K>
+ using contains = typename detail::contains_impl<L, K>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template<class... Ts>
+ struct make_set;
+ template<class U, class K>
+ struct set_erase_pred_impl
+ {
+ using type = list<U>;
+ };
+ template<class K>
+ struct set_erase_pred_impl<K,K>
+ {
+ using type = list<>;
+ };
+ template <class... T>
+ struct set_impl
+ {
+ template <typename K, typename = decltype(static_cast<type_<K>*>(static_cast<make_set<T...>*>(nullptr)))>
+ static std::true_type contains(type_<K>);
+ template <typename K>
+ static std::false_type contains(K);
+ template <typename K, typename = decltype(static_cast<type_<K>*>(static_cast<make_set<T...>*>(nullptr)))>
+ static std::true_type has_key(type_<K>);
+ template <typename K>
+ static std::false_type has_key(K);
+ template <class K>
+ static append<set_impl<>, typename set_erase_pred_impl<T, K>::type...> erase(type_<K>);
+ template<class K, class = decltype(static_cast<type_<K>*>(static_cast<make_set<T...>*>(nullptr)))>
+ static set_impl insert(type_<K>);
+ template<class K>
+ static set_impl<T..., typename K::type> insert(K);
+ };
+ template<class... Ts>
+ struct make_set : type_<Ts>...
+ {
+ using type = set_impl<Ts...>;
+ };
+}
+ template<class... Ts>
+ using set = typename detail::make_set<Ts...>::type;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <typename Pair>
+ struct get_second {
+ using type = typename Pair::second_type;
+ };
+}
+template <typename Map, template <class...> class Sequence = brigand::list>
+using values_as_sequence = transform<as_sequence<Map, Sequence>, detail::get_second<_1>>;
+}
+namespace brigand
+{
+namespace detail
+{
+ template <typename Pair>
+ struct get_first {
+ using type = typename Pair::first_type;
+ };
+}
+template <typename Map, template <class...> class Sequence = brigand::set>
+using keys_as_sequence = transform<as_sequence<Map, Sequence>, detail::get_first<_1>>;
+}
+namespace brigand
+{
+ struct empty_base {};
+}
+namespace brigand
+{
+ template<typename T, typename R = void > struct has_type
+ {
+ using type = R;
+ };
+}
+namespace brigand
+{
+ template<typename... Ts> struct inherit;
+ template<typename T> struct inherit<T>
+ {
+ struct type : public T {};
+ };
+ template<> struct inherit<>
+ {
+ using type = empty_base;
+ };
+ template<> struct inherit<empty_base>
+ {
+ using type = empty_base;
+ };
+ template<typename T1, typename T2> struct inherit<T1,T2>
+ {
+ struct type : public T1, T2 {};
+ };
+ template<typename T1> struct inherit<T1,empty_base>
+ {
+ using type = T1;
+ };
+ template<typename T2> struct inherit<empty_base,T2>
+ {
+ using type = T2;
+ };
+ template<> struct inherit<empty_base,empty_base>
+ {
+ using type = empty_base;
+ };
+ template<typename T1, typename T2, typename T3, typename... Ts>
+ struct inherit<T1, T2, T3, Ts...>
+ : inherit<T1, typename inherit<T2,typename inherit<T3, Ts...>::type>::type>
+ {};
+}
+namespace brigand
+{
+ namespace lazy
+ {
+ template< typename Types
+ , typename Node
+ , typename Root = brigand::empty_base
+ >
+ struct inherit_linearly;
+ template< typename Types
+ , template<typename...> class Node, typename...Ts
+ , typename Root
+ >
+ struct inherit_linearly<Types,Node<Ts...>,Root>
+ {
+ using type = brigand::fold<Types,Root,bind<Node,Ts...>>;
+ };
+ }
+ template< typename Types
+ , typename Node
+ , typename Root = brigand::empty_base
+ >
+ using inherit_linearly = typename lazy::inherit_linearly<Types,Node,Root>::type;
+}
+
+namespace brigand
+{
+ template<typename RealType, typename Type, Type Value>
+ struct real_ : std::integral_constant<Type,Value>
+ {
+ using value_type = RealType;
+ using parent = std::integral_constant<Type,Value>;
+ inline operator value_type() const
+ {
+ value_type that;
+ std::memcpy(&that, &parent::value, sizeof(value_type));
+ return that;
+ }
+ };
+ template<std::uint32_t Value>
+ struct single_ : real_<float, std::uint32_t, Value> {};
+ template<std::uint64_t Value>
+ struct double_ : real_<double, std::uint64_t,Value> {};
+}
</ins></span></pre></div>
<a id="trunkSourceWTFwtfCMakeListstxt"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/CMakeLists.txt (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/CMakeLists.txt        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WTF/wtf/CMakeLists.txt        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -7,6 +7,7 @@
</span><span class="cx"> BagToHashMap.h
</span><span class="cx"> BitVector.h
</span><span class="cx"> Bitmap.h
</span><ins>+ Brigand.h
</ins><span class="cx"> BubbleSort.h
</span><span class="cx"> BumpPointerAllocator.h
</span><span class="cx"> ByteOrder.h
</span></span></pre></div>
<a id="trunkSourceWTFwtfStdLibExtrash"></a>
<div class="modfile"><h4>Modified: trunk/Source/WTF/wtf/StdLibExtras.h (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WTF/wtf/StdLibExtras.h        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WTF/wtf/StdLibExtras.h        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -365,6 +365,43 @@
</span><span class="cx"> return Visitor<F...>(f...);
</span><span class="cx"> }
</span><span class="cx">
</span><ins>+namespace Detail
+{
+ template <typename, template <typename...> class>
+ struct IsTemplate_ : std::false_type
+ {
+ };
+
+ template <typename... Ts, template <typename...> class C>
+ struct IsTemplate_<C<Ts...>, C> : std::true_type
+ {
+ };
+}
+
+template <typename T, template <typename...> class Template>
+struct IsTemplate : public std::integral_constant<bool, Detail::IsTemplate_<T, Template>::value> {};
+
+namespace Detail
+{
+ template <template <typename...> class Base, typename Derived>
+ struct IsBaseOfTemplateImpl
+ {
+ template <typename... Args>
+ static std::true_type test(Base<Args...>*);
+ static std::false_type test(void*);
+
+ static constexpr const bool value = decltype(test(std::declval<typename std::remove_cv<Derived>::type*>()))::value;
+ };
+}
+
+template <template <typename...> class Base, typename Derived>
+struct IsBaseOfTemplate : public std::integral_constant<bool, Detail::IsBaseOfTemplateImpl<Base, Derived>::value> {};
+
+template <class T>
+struct RemoveCVAndReference {
+ typedef typename std::remove_cv<typename std::remove_reference<T>::type>::type type;
+};
+
</ins><span class="cx"> } // namespace WTF
</span><span class="cx">
</span><span class="cx"> // This version of placement new omits a 0 check.
</span></span></pre></div>
<a id="trunkSourceWebCoreChangeLog"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/ChangeLog (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/ChangeLog        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WebCore/ChangeLog        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -1,3 +1,43 @@
</span><ins>+2016-09-29 Sam Weinig <sam@webkit.org>
+
+ Add initial support for IDL union conversion
+ https://bugs.webkit.org/show_bug.cgi?id=161576
+
+ Reviewed by Chris Dumez.
+
+ * WebCore.xcodeproj/project.pbxproj:
+ Add IDLTypes.h
+
+ * bindings/generic/IDLTypes.h: Added.
+ Add a basic type hierarchy for types defined by WebIDL and their corresponding
+ WebCore implementation types.
+
+ * bindings/js/JSDOMConvert.h:
+ (WebCore::Converter<IDLDOMString>::convert):
+ (WebCore::Converter<IDLUSVString>::convert):
+ Add Converters for IDLDOMString and IDLUSVString.
+
+ (WebCore::ConditionalConverter<typename ReturnType, typename T, bool enabled>)
+ Add a struct to allow conditional conversion of types based on a compile boolean
+ value. This allows the union code to work, by ensuring that code for types that don't
+ exist doesn't get compiled.
+
+ (WebCore::Converter<IDLUnion>::convert):
+ Add template meta programming based version of the WebIDL conversion algorithm. It uses
+ introspection of the typelist to conditionally execute the parts of the algorithm that
+ apply and relies on the compiler eliminate the dead code it produces. This initial cut
+ doesn't implement the full algorithm, just a subset needed to see if this method will work
+ out.
+
+ * bindings/js/JSDOMWrapper.h:
+ (WebCore::isJSDOMWrapperType):
+ Add JSDOMWrapperType to the list of well known types to allow quick checking of wrappers
+ by the union code.
+
+ * bindings/js/JSNodeOrString.cpp:
+ (WebCore::toNodeOrStringVector):
+ Switch to new IDLUnion based converter.
+
</ins><span class="cx"> 2016-09-30 Myles C. Maxfield <mmaxfield@apple.com>
</span><span class="cx">
</span><span class="cx"> Implement animation of font-variation-settings
</span></span></pre></div>
<a id="trunkSourceWebCoreWebCorexcodeprojprojectpbxproj"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -2772,6 +2772,7 @@
</span><span class="cx">                 7C93F34E1AA6BF0700A98BAB /* ContentExtensionCompiler.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C93F34C1AA6BF0700A98BAB /* ContentExtensionCompiler.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 7C9DBFED1A9C49B1000D6B25 /* JSHTMLAttachmentElement.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7C9DBFEB1A9C49B1000D6B25 /* JSHTMLAttachmentElement.cpp */; };
</span><span class="cx">                 7C9DBFEE1A9C49B1000D6B25 /* JSHTMLAttachmentElement.h in Headers */ = {isa = PBXBuildFile; fileRef = 7C9DBFEC1A9C49B1000D6B25 /* JSHTMLAttachmentElement.h */; };
</span><ins>+                7CC16FFB1D77375300CE0877 /* IDLTypes.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC16FFA1D77375300CE0877 /* IDLTypes.h */; };
</ins><span class="cx">                 7CC289DF1AA0FE5D009A9CE3 /* URLRegistry.h in Headers */ = {isa = PBXBuildFile; fileRef = CDEE393817974274001D7580 /* URLRegistry.h */; settings = {ATTRIBUTES = (Private, ); }; };
</span><span class="cx">                 7CC564B818BABEA6001B9652 /* TelephoneNumberDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = 7CC564B618BABEA6001B9652 /* TelephoneNumberDetector.h */; };
</span><span class="cx">                 7CC564BA18BAC720001B9652 /* TelephoneNumberDetectorCocoa.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 7CC564B918BAC720001B9652 /* TelephoneNumberDetectorCocoa.cpp */; };
</span><span class="lines">@@ -9880,6 +9881,7 @@
</span><span class="cx">                 7C9DBFEA1A9C489F000D6B25 /* HTMLAttachmentElement.idl */ = {isa = PBXFileReference; lastKnownFileType = text; path = HTMLAttachmentElement.idl; sourceTree = "<group>"; };
</span><span class="cx">                 7C9DBFEB1A9C49B1000D6B25 /* JSHTMLAttachmentElement.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSHTMLAttachmentElement.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7C9DBFEC1A9C49B1000D6B25 /* JSHTMLAttachmentElement.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = JSHTMLAttachmentElement.h; sourceTree = "<group>"; };
</span><ins>+                7CC16FFA1D77375300CE0877 /* IDLTypes.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = IDLTypes.h; sourceTree = "<group>"; };
</ins><span class="cx">                 7CC564B618BABEA6001B9652 /* TelephoneNumberDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TelephoneNumberDetector.h; sourceTree = "<group>"; };
</span><span class="cx">                 7CC564B918BAC720001B9652 /* TelephoneNumberDetectorCocoa.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TelephoneNumberDetectorCocoa.cpp; sourceTree = "<group>"; };
</span><span class="cx">                 7CC6993E191EC5F500AF2270 /* JSWebKitNamespace.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = JSWebKitNamespace.cpp; sourceTree = "<group>"; };
</span><span class="lines">@@ -20964,6 +20966,7 @@
</span><span class="cx">                 B5D31DF711CF60E5009F22B4 /* generic */ = {
</span><span class="cx">                         isa = PBXGroup;
</span><span class="cx">                         children = (
</span><ins>+                                7CC16FFA1D77375300CE0877 /* IDLTypes.h */,
</ins><span class="cx">                                 B5D31DF811CF610B009F22B4 /* ActiveDOMCallback.cpp */,
</span><span class="cx">                                 B5D31DF911CF610B009F22B4 /* ActiveDOMCallback.h */,
</span><span class="cx">                         );
</span><span class="lines">@@ -24912,6 +24915,7 @@
</span><span class="cx">                                 3198480C1A1E6CE800A13318 /* JSAnimationEvent.h in Headers */,
</span><span class="cx">                                 1221E06D1C03D224006A1A00 /* JSAnimationTimeline.h in Headers */,
</span><span class="cx">                                 1AE96A8B1D1A0DDD00B86768 /* JSApplePayPaymentAuthorizedEvent.h in Headers */,
</span><ins>+                                7CC16FFB1D77375300CE0877 /* IDLTypes.h in Headers */,
</ins><span class="cx">                                 1AE96A8D1D1A0DDD00B86768 /* JSApplePayPaymentMethodSelectedEvent.h in Headers */,
</span><span class="cx">                                 1AE96A8F1D1A0DDD00B86768 /* JSApplePaySession.h in Headers */,
</span><span class="cx">                                 1AE96A911D1A0DDD00B86768 /* JSApplePayShippingContactSelectedEvent.h in Headers */,
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsgenericIDLTypesh"></a>
<div class="addfile"><h4>Added: trunk/Source/WebCore/bindings/generic/IDLTypes.h (0 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/generic/IDLTypes.h         (rev 0)
+++ trunk/Source/WebCore/bindings/generic/IDLTypes.h        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -0,0 +1,132 @@
</span><ins>+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include <wtf/Brigand.h>
+#include <wtf/StdLibExtras.h>
+
+namespace JSC {
+class JSValue;
+}
+
+namespace WebCore {
+
+template <typename Value> class DOMPromise;
+
+template<typename T>
+struct IDLType {
+ using ImplementationType = T;
+ using NullableType = Optional<ImplementationType>;
+};
+
+struct IDLDummy;
+
+// IDLUnsupportedType is a special type that serves as a base class for currently unsupported types.
+struct IDLUnsupportedType : IDLType<void> { };
+
+// IDLNull is a special type for use as a subtype in an IDLUnion that is nullable.
+struct IDLNull : IDLType<std::nullptr_t> { };
+
+struct IDLAny : IDLType<JSC::JSValue> { };
+
+struct IDLBoolean : IDLType<bool> { };
+
+template<typename NumericType> struct IDLNumber : IDLType<NumericType> { };
+
+template<typename IntegerType> struct IDLInteger : IDLNumber<IntegerType> { };
+struct IDLByte : IDLInteger<int8_t> { };
+struct IDLOctet : IDLInteger<uint8_t> { };
+struct IDLShort : IDLInteger<int16_t> { };
+struct IDLUnsignedShort : IDLInteger<uint16_t> { };
+struct IDLLong : IDLInteger<int32_t> { };
+struct IDLUnsignedLong : IDLInteger<uint32_t> { };
+struct IDLLongLong : IDLInteger<int64_t> { };
+struct IDLUnsignedLongLong : IDLInteger<uint64_t> { };
+
+template<typename FloatingPointType, bool unrestricted = false> struct IDLFloatingPoint : IDLNumber<FloatingPointType> {
+ static constexpr bool isUnrestricted = unrestricted;
+};
+struct IDLFloat : IDLFloatingPoint<float> { };
+struct IDLUnrestrictedFloat : IDLFloatingPoint<float, true> { };
+struct IDLDouble : IDLFloatingPoint<double> { };
+struct IDLUnrestrictedDouble : IDLFloatingPoint<double, true> { };
+
+struct IDLString : IDLType<String> {
+ using NullableType = String;
+};
+struct IDLDOMString : IDLString { };
+struct IDLByteString : IDLUnsupportedType { };
+struct IDLUSVString : IDLString { };
+
+struct IDLObject : IDLUnsupportedType { };
+
+template<typename T> struct IDLInterface : IDLType<Ref<T>> {
+ using RawType = T;
+ using NullableType = RefPtr<T>;
+};
+
+template<typename T> struct IDLDictionary : IDLType<T> { };
+template<typename T> struct IDLEnumeration : IDLType<T> { };
+template<typename T> struct IDLCallbackFunction : IDLUnsupportedType { };
+
+template<typename T> struct IDLNullable : IDLType<typename T::NullableType> {
+ using InnerType = T;
+};
+
+template<typename T> struct IDLSequence : IDLType<Vector<typename T::ImplementationType>> {
+ using InnerType = T;
+};
+
+template<typename T> struct IDLFrozenArray : IDLType<Vector<typename T::ImplementationType>> {
+ using InnerType = T;
+};
+
+template<typename T> struct IDLPromise : IDLType<DOMPromise<T>> {
+ using InnerType = T;
+};
+
+struct IDLRegExp : IDLUnsupportedType { };
+struct IDLError : IDLUnsupportedType { };
+struct IDLDOMException : IDLUnsupportedType { };
+
+template<typename... Ts>
+struct IDLUnion : IDLType<std::experimental::variant<typename Ts::ImplementationType...>> {
+ using TypeList = brigand::list<Ts...>;
+};
+
+
+// Helper predicates
+
+template <typename T>
+struct IsIDLInterface : public std::integral_constant<bool, WTF::IsTemplate<T, IDLInterface>::value> { };
+
+template <typename T>
+struct IsIDLDictionary : public std::integral_constant<bool, WTF::IsTemplate<T, IDLDictionary>::value> { };
+
+template <typename T>
+struct IsIDLNumber : public std::integral_constant<bool, WTF::IsBaseOfTemplate<IDLNumber, T>::value> { };
+
+} // namespace WebCore
</ins></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMConverth"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMConvert.h (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMConvert.h        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WebCore/bindings/js/JSDOMConvert.h        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -1,31 +1,31 @@
</span><span class="cx"> /*
</span><ins>+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
+ * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ */
</ins><span class="cx">
</span><del>-Copyright (C) 2016 Apple Inc. All rights reserved.
-
-Redistribution and use in source and binary forms, with or without
-modification, are permitted provided that the following conditions
-are met:
-1. Redistributions of source code must retain the above copyright
- notice, this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright
- notice, this list of conditions and the following disclaimer in the
- documentation and/or other materials provided with the distribution.
-
-THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS'' AND ANY
-EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
-WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS BE LIABLE FOR ANY
-DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
-(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
-LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
-ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-*/
-
</del><span class="cx"> #pragma once
</span><span class="cx">
</span><ins>+#include "IDLTypes.h"
</ins><span class="cx"> #include "JSDOMBinding.h"
</span><span class="cx">
</span><span class="cx"> namespace WebCore {
</span><span class="lines">@@ -133,6 +133,22 @@
</span><span class="cx"> }
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+template<> struct Converter<IDLDOMString> : DefaultConverter<String> {
+ using OptionalValue = String; // Use null string to mean an optional value was not present.
+ static String convert(JSC::ExecState& state, JSC::JSValue value)
+ {
+ return value.toWTFString(&state);
+ }
+};
+
+template<> struct Converter<IDLUSVString> : DefaultConverter<String> {
+ using OptionalValue = String; // Use null string to mean an optional value was not present.
+ static String convert(JSC::ExecState& state, JSC::JSValue value)
+ {
+ return valueToUSVString(&state, value);
+ }
+};
+
</ins><span class="cx"> template<> struct Converter<JSC::JSValue> : DefaultConverter<JSC::JSValue> {
</span><span class="cx"> using OptionalValue = JSC::JSValue; // Use jsUndefined() to mean an optional value was not present.
</span><span class="cx"> static JSC::JSValue convert(JSC::ExecState&, JSC::JSValue value)
</span><span class="lines">@@ -286,4 +302,148 @@
</span><span class="cx"> }
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+template<typename ReturnType, typename T, bool enabled>
+struct ConditionalConverter;
+
+template<typename ReturnType, typename T>
+struct ConditionalConverter<ReturnType, T, true> {
+ static Optional<ReturnType> convert(JSC::ExecState& state, JSC::JSValue value)
+ {
+ return ReturnType(Converter<T>::convert(state, value));
+ }
+};
+
+template<typename ReturnType, typename T>
+struct ConditionalConverter<ReturnType, T, false> {
+ static Optional<ReturnType> convert(JSC::ExecState&, JSC::JSValue)
+ {
+ return Nullopt;
+ }
+};
+
+namespace Detail {
+ template<typename List, bool condition>
+ struct ConditionalFront;
+
+ template<typename List>
+ struct ConditionalFront<List, true>
+ {
+ using type = brigand::front<List>;
+ };
+
+ template<typename List>
+ struct ConditionalFront<List, false>
+ {
+ using type = void;
+ };
+}
+
+template<typename List, bool condition>
+using ConditionalFront = typename Detail::ConditionalFront<List, condition>::type;
+
+template<typename... T>
+struct Converter<IDLUnion<T...>> : DefaultConverter<typename IDLUnion<T...>::ImplementationType>
+{
+ using Type = IDLUnion<T...>;
+ using TypeList = typename Type::TypeList;
+ using ReturnType = typename Type::ImplementationType;
+
+ using DictionaryTypeList = brigand::find<TypeList, IsIDLDictionary<brigand::_1>>;
+ using DictionaryType = ConditionalFront<DictionaryTypeList, brigand::size<DictionaryTypeList>::value != 0>;
+ static_assert(brigand::size<DictionaryTypeList>::value == 0 || brigand::size<DictionaryTypeList>::value == 1, "There can be 0 or 1 dictionary types in an IDLUnion.");
+
+ using NumericTypeList = brigand::find<TypeList, IsIDLNumber<brigand::_1>>;
+ using NumericType = ConditionalFront<NumericTypeList, brigand::size<NumericTypeList>::value != 0>;
+ static_assert(brigand::size<NumericTypeList>::value == 0 || brigand::size<NumericTypeList>::value == 1, "There can be 0 or 1 numeric types in an IDLUnion.");
+
+ using StringTypeList = brigand::find<TypeList, std::is_base_of<IDLString, brigand::_1>>;
+ using StringType = ConditionalFront<StringTypeList, brigand::size<StringTypeList>::value != 0>;
+ static_assert(brigand::size<StringTypeList>::value == 0 || brigand::size<StringTypeList>::value == 1, "There can be 0 or 1 string types in an IDLUnion.");
+
+ using InterfaceTypeList = brigand::filter<TypeList, IsIDLInterface<brigand::_1>>;
+
+ static ReturnType convert(JSC::ExecState& state, JSC::JSValue value)
+ {
+ auto scope = DECLARE_THROW_SCOPE(state.vm());
+
+ // 1. If the union type includes a nullable type and V is null or undefined, then return the IDL value null.
+ constexpr bool hasNullType = brigand::any<TypeList, std::is_same<IDLNull, brigand::_1>>::value;
+ if (hasNullType) {
+ if (value.isUndefinedOrNull())
+ return std::move<WTF::CheckMoveParameter>(ConditionalConverter<ReturnType, IDLNull, hasNullType>::convert(state, value).value());
+ }
+
+ // 2. Let types be the flattened member types of the union type.
+ // NOTE: Union is expected to be pre-flattented.
+
+ // 3. If V is null or undefined, and types includes a dictionary type, then return the result of converting V to that dictionary type.
+ constexpr bool hasDictionaryType = brigand::size<DictionaryTypeList>::value != 0;
+ if (hasDictionaryType) {
+ if (value.isUndefinedOrNull())
+ return std::move<WTF::CheckMoveParameter>(ConditionalConverter<ReturnType, DictionaryType, hasDictionaryType>::convert(state, value).value());
+ }
+
+ // 4. If V is a platform object, then:
+ // 1. If types includes an interface type that V implements, then return the IDL value that is a reference to the object V.
+ // 2. If types includes object, then return the IDL value that is a reference to the object V.
+ // (FIXME: Add support for object and step 4.2)
+ if (brigand::any<TypeList, IsIDLInterface<brigand::_1>>::value) {
+ if (isJSDOMWrapperType(value)) {
+ Optional<ReturnType> returnValue;
+ brigand::for_each<InterfaceTypeList>([&](auto&& type) {
+ if (returnValue)
+ return;
+
+ using ImplementationType = typename WTF::RemoveCVAndReference<decltype(type)>::type::type::RawType;
+ using WrapperType = typename JSDOMWrapperConverterTraits<ImplementationType>::WrapperClass;
+
+ auto* castedValue = JSC::jsDynamicCast<WrapperType*>(value);
+ if (!castedValue)
+ return;
+
+ returnValue = ReturnType(castedValue->wrapped());
+ });
+ ASSERT(returnValue);
+
+ return WTFMove(returnValue.value());
+ }
+ }
+
+ // FIXME: Add support for steps 5 - 12.
+
+ // 13. If V is a Boolean value, then:
+ // 1. If types includes a boolean, then return the result of converting V to boolean.
+ constexpr bool hasBooleanType = brigand::any<TypeList, std::is_same<IDLBoolean, brigand::_1>>::value;
+ if (hasBooleanType) {
+ if (value.isBoolean())
+ return std::move<WTF::CheckMoveParameter>(ConditionalConverter<ReturnType, bool, hasBooleanType>::convert(state, value).value());
+ }
+
+ // 14. If V is a Number value, then:
+ // 1. If types includes a numeric type, then return the result of converting V to that numeric type.
+ constexpr bool hasNumericType = brigand::size<NumericTypeList>::value != 0;
+ if (hasNumericType) {
+ if (value.isNumber())
+ return std::move<WTF::CheckMoveParameter>(ConditionalConverter<ReturnType, NumericType, hasNumericType>::convert(state, value).value());
+ }
+
+ // 15. If types includes a string type, then return the result of converting V to that type.
+ constexpr bool hasStringType = brigand::size<StringTypeList>::value != 0;
+ if (hasStringType)
+ return std::move<WTF::CheckMoveParameter>(ConditionalConverter<ReturnType, StringType, hasStringType>::convert(state, value).value());
+
+ // 16. If types includes a numeric type, then return the result of converting V to that numeric type.
+ if (hasNumericType)
+ return std::move<WTF::CheckMoveParameter>(ConditionalConverter<ReturnType, NumericType, hasNumericType>::convert(state, value).value());
+
+ // 17. If types includes a boolean, then return the result of converting V to boolean.
+ if (hasBooleanType)
+ return std::move<WTF::CheckMoveParameter>(ConditionalConverter<ReturnType, bool, hasBooleanType>::convert(state, value).value());
+
+ // 18. Throw a TypeError.
+ throwTypeError(&state, scope);
+ return ReturnType();
+ }
+};
+
</ins><span class="cx"> } // namespace WebCore
</span></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSDOMWrapperh"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSDOMWrapper.h (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSDOMWrapper.h        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WebCore/bindings/js/JSDOMWrapper.h        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -19,8 +19,7 @@
</span><span class="cx"> * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
</span><span class="cx"> */
</span><span class="cx">
</span><del>-#ifndef JSDOMWrapper_h
-#define JSDOMWrapper_h
</del><ins>+#pragma once
</ins><span class="cx">
</span><span class="cx"> #include "JSDOMGlobalObject.h"
</span><span class="cx"> #include <runtime/JSDestructibleObject.h>
</span><span class="lines">@@ -30,9 +29,10 @@
</span><span class="cx"> class JSDOMWindow;
</span><span class="cx"> class ScriptExecutionContext;
</span><span class="cx">
</span><del>-static const uint8_t JSNodeType = JSC::LastJSCObjectType + 1;
-static const uint8_t JSDocumentWrapperType = JSC::LastJSCObjectType + 2;
-static const uint8_t JSElementType = JSC::LastJSCObjectType + 3;
</del><ins>+static const uint8_t JSDOMWrapperType = JSC::LastJSCObjectType + 1;
+static const uint8_t JSNodeType = JSC::LastJSCObjectType + 2;
+static const uint8_t JSDocumentWrapperType = JSC::LastJSCObjectType + 3;
+static const uint8_t JSElementType = JSC::LastJSCObjectType + 4;
</ins><span class="cx">
</span><span class="cx"> class JSDOMObject : public JSC::JSDestructibleObject {
</span><span class="cx"> public:
</span><span class="lines">@@ -69,6 +69,13 @@
</span><span class="cx"> Ref<ImplementationClass> m_wrapped;
</span><span class="cx"> };
</span><span class="cx">
</span><ins>+ALWAYS_INLINE bool isJSDOMWrapperType(JSC::JSValue value)
+{
+ if (UNLIKELY(!value.isCell()))
+ return false;
+ return value.asCell()->type() >= JSDOMWrapperType;
+}
+
</ins><span class="cx"> template<typename ImplementationClass> struct JSDOMWrapperConverterTraits;
</span><span class="cx">
</span><span class="cx"> template<typename JSClass, typename Enable = void>
</span><span class="lines">@@ -92,5 +99,3 @@
</span><span class="cx"> };
</span><span class="cx">
</span><span class="cx"> } // namespace WebCore
</span><del>-
-#endif // JSDOMWrapper_h
</del></span></pre></div>
<a id="trunkSourceWebCorebindingsjsJSNodeOrStringcpp"></a>
<div class="modfile"><h4>Modified: trunk/Source/WebCore/bindings/js/JSNodeOrString.cpp (206690 => 206691)</h4>
<pre class="diff"><span>
<span class="info">--- trunk/Source/WebCore/bindings/js/JSNodeOrString.cpp        2016-09-30 23:08:02 UTC (rev 206690)
+++ trunk/Source/WebCore/bindings/js/JSNodeOrString.cpp        2016-09-30 23:10:31 UTC (rev 206691)
</span><span class="lines">@@ -26,6 +26,8 @@
</span><span class="cx"> #include "config.h"
</span><span class="cx"> #include "JSNodeOrString.h"
</span><span class="cx">
</span><ins>+#include "IDLTypes.h"
+#include "JSDOMConvert.h"
</ins><span class="cx"> #include "JSNode.h"
</span><span class="cx"> #include <JavaScriptCore/JSString.h>
</span><span class="cx"> #include <JavaScriptCore/ThrowScope.h>
</span><span class="lines">@@ -36,23 +38,31 @@
</span><span class="cx">
</span><span class="cx"> Vector<std::experimental::variant<Ref<Node>, String>> toNodeOrStringVector(ExecState& state)
</span><span class="cx"> {
</span><ins>+ using NodeOrStringType = IDLUnion<IDLInterface<Node>, IDLDOMString>;
+ using ConverterType = Converter<NodeOrStringType>;
+
+ using InterfaceTypeList = typename ConverterType::InterfaceTypeList;
+ using InterfaceType = brigand::front<InterfaceTypeList>;
+ static_assert(std::is_same<InterfaceType, IDLInterface<Node>>::value, "");
+ static_assert(brigand::size<InterfaceTypeList>::value == 1, "");
+
+ using StringTypeList = typename ConverterType::StringTypeList;
+ using StringType = typename ConverterType::StringType;
+ static_assert(std::is_same<StringType, IDLDOMString>::value, "");
+ static_assert(brigand::size<StringTypeList>::value == 1, "");
+
</ins><span class="cx"> VM& vm = state.vm();
</span><span class="cx"> auto scope = DECLARE_THROW_SCOPE(vm);
</span><span class="cx">
</span><span class="cx"> size_t argumentCount = state.argumentCount();
</span><span class="cx">
</span><del>- Vector<std::experimental::variant<Ref<Node>, String>> result;
</del><ins>+ Vector<typename NodeOrStringType::ImplementationType> result;
</ins><span class="cx"> result.reserveInitialCapacity(argumentCount);
</span><span class="cx">
</span><span class="cx"> for (size_t i = 0; i < argumentCount; ++i) {
</span><del>- JSValue value = state.uncheckedArgument(i);
- if (auto* node = jsDynamicCast<JSNode*>(value))
- result.uncheckedAppend(node->wrapped());
- else {
- String string = value.toWTFString(&state);
- RETURN_IF_EXCEPTION(scope, { });
- result.uncheckedAppend(string);
- }
</del><ins>+ auto item = ConverterType::convert(state, state.uncheckedArgument(i));
+ RETURN_IF_EXCEPTION(scope, { });
+ result.uncheckedAppend(WTFMove(item));
</ins><span class="cx"> }
</span><span class="cx">
</span><span class="cx"> return result;
</span></span></pre>
</div>
</div>
</body>
</html>