text:
/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License. You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied. See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */

#include <thrift/thrift-config.h>

#include <thrift/concurrency/Monitor.h>
#include <thrift/concurrency/Exception.h>
#include <thrift/concurrency/Util.h>
#include <thrift/transport/PlatformSocket.h>
#include <assert.h>

#include <boost/scoped_ptr.hpp>
#include <boost/thread.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>

namespace apache { namespace thrift { namespace concurrency {

/**
 * Monitor implementation using the boost thread library
 *
 * @version $Id:$
 */
class Monitor::Impl : public boost::condition_variable_any {

 public:

  Impl()
     : ownedMutex_(new Mutex()),
       mutex_(NULL) {
    init(ownedMutex_.get());
  }

  Impl(Mutex* mutex)
     : mutex_(NULL) {
    init(mutex);
  }

  Impl(Monitor* monitor)
     : mutex_(NULL) {
    init(&(monitor->mutex()));
  }

  Mutex& mutex() { return *mutex_; }
  void lock() { mutex().lock(); }
  void unlock() { mutex().unlock(); }

  /**
   * Exception-throwing version of waitForTimeRelative(), called simply
   * wait(int64) for historical reasons.  Timeout is in milliseconds.
   *
   * If the condition occurs,  this function returns cleanly; on timeout or
   * error an exception is thrown.
   */
  void wait(int64_t timeout_ms) {
    int result = waitForTimeRelative(timeout_ms);
    if (result == THRIFT_ETIMEDOUT) {
      throw TimedOutException();
    } else if (result != 0) {
      throw TException(
        "Monitor::wait() failed");
    }
  }

  /**
   * Waits until the specified timeout in milliseconds for the condition to
   * occur, or waits forever if timeout_ms == 0.
   *
   * Returns 0 if condition occurs, THRIFT_ETIMEDOUT on timeout, or an error code.
   */
  int waitForTimeRelative(int64_t timeout_ms) {
    if (timeout_ms == 0LL) {
      return waitForever();
    }

    assert(mutex_);
	boost::timed_mutex* mutexImpl =
      reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
    assert(mutexImpl);

	boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
	int res = timed_wait(lock, boost::get_system_time()+boost::posix_time::milliseconds(timeout_ms)) ? 0 : THRIFT_ETIMEDOUT;
	lock.release();
	return res;
  }

  /**
   * Waits until the absolute time specified using struct THRIFT_TIMESPEC.
   * Returns 0 if condition occurs, THRIFT_ETIMEDOUT on timeout, or an error code.
   */
  int waitForTime(const THRIFT_TIMESPEC* abstime) {
    struct timeval temp;
    temp.tv_sec  = static_cast<long>(abstime->tv_sec);
    temp.tv_usec = static_cast<long>(abstime->tv_nsec) / 1000;
    return waitForTime(&temp);
  }

  /**
   * Waits until the absolute time specified using struct timeval.
   * Returns 0 if condition occurs, THRIFT_ETIMEDOUT on timeout, or an error code.
   */
  int waitForTime(const struct timeval* abstime) {
    assert(mutex_);
    boost::timed_mutex* mutexImpl =
      static_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
    assert(mutexImpl);

    struct timeval currenttime;
    Util::toTimeval(currenttime, Util::currentTime());

	long tv_sec = static_cast<long>(abstime->tv_sec - currenttime.tv_sec);
	long tv_usec = static_cast<long>(abstime->tv_usec - currenttime.tv_usec);
	if(tv_sec < 0)
		tv_sec = 0;
	if(tv_usec < 0)
		tv_usec = 0;

	boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
	int res = timed_wait(lock, boost::get_system_time() +
		boost::posix_time::seconds(tv_sec) +
		boost::posix_time::microseconds(tv_usec)
		) ? 0 : THRIFT_ETIMEDOUT;
	lock.release();
	return res;
  }

  /**
   * Waits forever until the condition occurs.
   * Returns 0 if condition occurs, or an error code otherwise.
   */
  int waitForever() {
    assert(mutex_);
    boost::timed_mutex* mutexImpl =
      reinterpret_cast<boost::timed_mutex*>(mutex_->getUnderlyingImpl());
    assert(mutexImpl);

	boost::timed_mutex::scoped_lock lock(*mutexImpl, boost::adopt_lock);
	((boost::condition_variable_any*)this)->wait(lock);
	lock.release();
    return 0;
  }

  void notify() {
	  notify_one();
  }

  void notifyAll() {
	  notify_all();
  }

 private:

  void init(Mutex* mutex) {
    mutex_ = mutex;
  }

  boost::scoped_ptr<Mutex> ownedMutex_;
  Mutex* mutex_;
};

Monitor::Monitor() : impl_(new Monitor::Impl()) {}
Monitor::Monitor(Mutex* mutex) : impl_(new Monitor::Impl(mutex)) {}
Monitor::Monitor(Monitor* monitor) : impl_(new Monitor::Impl(monitor)) {}

Monitor::~Monitor() { delete impl_; }

Mutex& Monitor::mutex() const { return const_cast<Monitor::Impl*>(impl_)->mutex(); }

void Monitor::lock() const { const_cast<Monitor::Impl*>(impl_)->lock(); }

void Monitor::unlock() const { const_cast<Monitor::Impl*>(impl_)->unlock(); }

void Monitor::wait(int64_t timeout) const { const_cast<Monitor::Impl*>(impl_)->wait(timeout); }

int Monitor::waitForTime(const THRIFT_TIMESPEC* abstime) const {
  return const_cast<Monitor::Impl*>(impl_)->waitForTime(abstime);
}

int Monitor::waitForTime(const timeval* abstime) const {
  return const_cast<Monitor::Impl*>(impl_)->waitForTime(abstime);
}

int Monitor::waitForTimeRelative(int64_t timeout_ms) const {
  return const_cast<Monitor::Impl*>(impl_)->waitForTimeRelative(timeout_ms);
}

int Monitor::waitForever() const {
  return const_cast<Monitor::Impl*>(impl_)->waitForever();
}

void Monitor::notify() const { const_cast<Monitor::Impl*>(impl_)->notify(); }

void Monitor::notifyAll() const { const_cast<Monitor::Impl*>(impl_)->notifyAll(); }

}}} // apache::thrift::concurrency

max_stars_repo_name: vmcraft/remoteprinter

max_issues_repo_name: vmcraft/remoteprinter

max_forks_repo_name: vmcraft/remoteprinter


text:
//==================================================================================================
/*!
  @file

    @copyright 2016 NumScale SAS

  Distributed under the Boost Software License, Version 1.0.
  (See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
*/
//==================================================================================================
#ifndef BOOST_SIMD_FUNCTION_SINH_HPP_INCLUDED
#define BOOST_SIMD_FUNCTION_SINH_HPP_INCLUDED

#if defined(DOXYGEN_ONLY)
namespace boost { namespace simd
{

  /*!

    @ingroup group-hyperbolic
    This function object returns the hyperbolic sine: \f$(e^{x}-e^{-x})/2\f$.

    @par Header <boost/simd/function/sinh.hpp>

    @see tanh, cosh, sech, csch, sinhcosh

    @par Example:

      @snippet sinh.cpp sinh

    @par Possible output:

      @snippet sinh.txt sinh
  **/
  IEEEValue sinh(IEEEValue const& x);
} }
#endif

#include <boost/simd/function/scalar/sinh.hpp>
#include <boost/simd/function/simd/sinh.hpp>

#endif

ext: hpp

max_stars_repo_name: SylvainCorlay/pythran

max_issues_repo_name: SylvainCorlay/pythran

max_forks_repo_name: SylvainCorlay/pythran


text:
/*!
@file
Forward declares `boost::hana::Iterable`.

@copyright Louis Dionne 2014
Distributed under the Boost Software License, Version 1.0.
(See accompanying file LICENSE.md or copy at http://boost.org/LICENSE_1_0.txt)
 */

#ifndef BOOST_HANA_ITERABLE_ITERABLE_HPP
#define BOOST_HANA_ITERABLE_ITERABLE_HPP

#include <boost/hana/core/typeclass.hpp>
#include <boost/hana/detail/constexpr.hpp>

namespace boost { namespace hana {
    namespace detail {
        struct FoldableFromIterable;
    }

    //! @ingroup group-typeclasses
    //! `Iterable` represents data structures supporting external iteration.
    //!
    //! ### Laws
    //! In a sense, `Foldable` represents data structures supporting internal
    //! iteration with the ability to accumulate a result. We request that
    //! instances of both `Iterable` and `Foldable` provide consistent
    //! instances. Hence, for any finite `Iterable` _and_ `Foldable` `it`,
    //! the following laws must be satisfied:
    //! @code
    //!     head(it) == head(to<List>(it))
    //!     to<List>(tail(it)) == tail(to<List>(it))
    //!     is_empty(it) if and only if is_empty(to<List>(it))
    //! @endcode
    //!
    //! This is basically saying that linearizing a `Foldable` and then
    //! iterating through it should be equivalent to iterating through it
    //! in the first place.
    struct Iterable {
        BOOST_HANA_TYPECLASS(Iterable);
        struct mcd;
    };

    //! Return the first element of a non-empty iterable.
    //! @relates Iterable
    //!
    //! ### Example
    //! @snippet example/iterable/head.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto head = [](auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::head_impl(iterable);
    };

    //! Return a new iterable containing all but the first element of a
    //! non-empty iterable.
    //! @relates Iterable
    //!
    //! ### Example
    //! @snippet example/iterable/tail.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto tail = [](auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::tail_impl(iterable);
    };

    //! Return whether the iterable is empty.
    //! @relates Iterable
    //!
    //! Specificaly, `is_empty` must return a [compile-time]
    //! (@ref Logical_terminology) `Logical` representing
    //! whether the iterable is empty.
    //!
    //! ### Example
    //! @snippet example/iterable/is_empty.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto is_empty = [](auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::is_empty_impl(iterable);
    };

    //! Return the `n`th element of an iterable.
    //! @relates Iterable
    //!
    //!
    //! @param n
    //! A non-negative `Integral` representing the 0-based index of the
    //! element to return. The iterable must contain at least `n + 1`
    //! elements.
    //!
    //! @param iterable
    //! The iterable in which an element is fetched.
    //!
    //!
    //! ### Example
    //! @snippet example/iterable/at.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto at = [](auto n, auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::at_impl(n, iterable);
    };

    //! Return the last element of a non-empty and finite iterable.
    //! @relates Iterable
    //!
    //! ### Example
    //! @snippet example/iterable/last.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto last = [](auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::last_impl(iterable);
    };

    //! Drop the first `n` elements of an iterable and return the rest.
    //! @relates Iterable
    //!
    //!
    //! @param n
    //! A non-negative `Integral` representing the number of elements to be
    //! dropped from the iterable. If `n` is greater than the number of
    //! elements in the iterable, the returned iterable is empty.
    //!
    //! @param iterable
    //! The iterable from which elements are dropped.
    //!
    //!
    //! ### Example
    //! @snippet example/iterable/drop.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto drop = [](auto n, auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::drop_impl(n, iterable);
    };

    //! Drop elements from an iterable up to, but excluding, the first
    //! element for which the `predicate` is not satisfied.
    //! @relates Iterable
    //!
    //! Specifically, `drop_while` returns an iterable containing all the
    //! elements of the original iterable except for those in the range
    //! delimited by [`head`, `e`), where `head` is the first element and
    //! `e` is the first element for which the `predicate` is not satisfied.
    //! If the iterable is not finite, the `predicate` has to return a false-
    //! valued `Logical` at a finite index for this method to return.
    //!
    //!
    //! @param predicate
    //! A function called as `predicate(x)`, where `x` is an element of the
    //! structure, and returning a `Logical` representing whether `x` should
    //! be dropped from the structure. In the current version of the library,
    //! `predicate` should return a [compile-time](@ref Logical_terminology)
    //! `Logical`.
    //!
    //! @param iterable
    //! The iterable from which elements are dropped.
    //!
    //!
    //! ### Example
    //! @snippet example/iterable/drop_while.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto drop_while = [](auto predicate, auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::drop_while_impl(predicate, iterable);
    };

    //! Drop elements from an iterable up to, but excluding, the first
    //! element for which the `predicate` is satisfied.
    //! @relates Iterable
    //!
    //! Specifically, `drop_until` returns an iterable containing all the
    //! elements of the original iterable except for those in the range
    //! delimited by [`head`, `e`), where `head` is the first element and
    //! `e` is the first element for which the `predicate` is satisfied.
    //! If the iterable is not finite, the `predicate` has to return a true-
    //! valued `Logical` at a finite index for this method to return.
    //!
    //! @note
    //! This is effectively equivalent to `drop_while` with a negated
    //! `predicate`.
    //!
    //!
    //! @param predicate
    //! A function called as `predicate(x)`, where `x` is an element of the
    //! structure, and returning a `Logical` representing whether `x` and
    //! subsequent elements should be kept in the structure. In the current
    //! version of the library, `predicate` should return a
    //! [compile-time](@ref Logical_terminology) `Logical`.
    //!
    //! @param iterable
    //! The iterable from which elements are dropped.
    //!
    //!
    //! ### Example
    //! @snippet example/iterable/drop_until.cpp main
    BOOST_HANA_CONSTEXPR_LAMBDA auto drop_until = [](auto predicate, auto iterable) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::drop_until_impl(predicate, iterable);
    };

    //! Perform an action on each element of an iterable, discarding
    //! the result each time.
    //! @relates Iterable
    //!
    //! Iteration is done in the same order as per repeatedly applying
    //! `tail` to the iterable. If the iterable is not finite, this method
    //! will not terminate.
    //!
    //!
    //! @param iterable
    //! The structure on which iteration is done.
    //!
    //! @param f
    //! A function called as `f(x)` for each element `x` of the iterable.
    //! The result of `f(x)`, whatever it is, is ignored.
    //!
    //!
    //! ### Example
    //! @snippet example/iterable/for_each.cpp main
    //!
    //! @todo
    //! The presence of implicit side effects in this function might be a
    //! smell that it should be moved to a different type class and handled
    //! through `Monad`s.
    BOOST_HANA_CONSTEXPR_LAMBDA auto for_each = [](auto iterable, auto f) {
        return Iterable::instance<
            datatype_t<decltype(iterable)>
        >::for_each_impl(iterable, f);
    };
}} // end namespace boost::hana

#endif // !BOOST_HANA_ITERABLE_ITERABLE_HPP

max_stars_repo_name: rbock/hana

max_issues_repo_name: rbock/hana

max_forks_repo_name: rbock/hana


text:
#include "camera_array/RandomArrayManager.h"
#include "argus_utils/random/RandomUtils.hpp"
#include <boost/foreach.hpp>

namespace argus
{

RandomArrayManager::RandomArrayManager( const ros::NodeHandle& nh,
                                        const ros::NodeHandle& ph )
: CameraArrayManager( nh, ph )
{

	boost::random::random_device rng;
	generator.seed( rng );

	cameraNames.reserve( cameraRegistry.size() );
	BOOST_FOREACH( const CameraRegistry::value_type& item, cameraRegistry )
	{
		cameraNames.push_back( item.first );
	}

  double updateRate;
  ph.param<double>( "update_rate", updateRate, 1.0 );
  timer = std::make_shared<ros::Timer>
    ( nodeHandle.createTimer( ros::Duration( 1.0/updateRate ),
			      &RandomArrayManager::TimerCallback,
			      this ) );

}

void RandomArrayManager::TimerCallback( const ros::TimerEvent& event )
{
	std::vector<unsigned int> cameraInds;
	BitmapSampling( cameraNames.size(), maxNumActive, cameraInds, generator );

	CameraSet active;
	for( unsigned int i = 0; i < cameraInds.size(); i++ )
	{
		active.insert( cameraNames[ cameraInds[i] ] );
		ROS_INFO_STREAM( "Activating " << cameraNames[ cameraInds[i] ] );
	}
	SetActiveCameras( active );
}

}

ext: cpp

max_stars_repo_name: Humhu/argus

max_issues_repo_name: Humhu/argus

max_forks_repo_name: Humhu/argus


text:
//==============================================================================
//         Copyright 2003 - 2012   LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2013   LRI    UMR 8623 CNRS/Univ Paris Sud XI
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef NT2_LINALG_FUNCTIONS_FACTORIZATIONS_CHOL_HPP_INCLUDED
#define NT2_LINALG_FUNCTIONS_FACTORIZATIONS_CHOL_HPP_INCLUDED

#include <nt2/linalg/functions/lu.hpp>
#include <nt2/include/functions/qr.hpp>
#include <nt2/include/functions/is_gtz.hpp>
#include <nt2/include/functions/potrf.hpp>
#include <nt2/include/functions/tie.hpp>
#include <nt2/include/functions/triu.hpp>
#include <nt2/include/functions/tril.hpp>
#include <nt2/linalg/details/utility/f77_wrapper.hpp>
#include <nt2/linalg/details/utility/lapack_verify.hpp>
#include <nt2/linalg/options.hpp>
#include <nt2/core/container/dsl/as_terminal.hpp>
#include <nt2/core/container/table/table.hpp>
#include <nt2/core/container/colon/colon.hpp>
#include <boost/assert.hpp>
#include <boost/dispatch/attributes.hpp>

namespace nt2 { namespace ext
{
  //============================================================================
  //CHOL Scalar
  //============================================================================
  BOOST_DISPATCH_IMPLEMENT  ( chol_, tag::cpu_
                            , (A0)
                            , (scalar_<unspecified_<A0> >)
                            )
  {
    typedef A0 result_type;

    BOOST_FORCEINLINE result_type operator()(const A0& a0) const
    {
      BOOST_ASSERT_MSG(is_gtz(a0), "Matrix must be positive definite");
      return  nt2::sqrt(a0);
    }
  };

  BOOST_DISPATCH_IMPLEMENT  ( chol_, tag::cpu_
                            , (A0)(A1)
                            , (scalar_<unspecified_<A0> >)
                              (unspecified_<A1>)
                            )
  {
    typedef typename nt2::meta::as_real<A0>::type result_type;

    BOOST_FORCEINLINE result_type operator()(const A0& a0, const A1&) const
    {
      BOOST_ASSERT_MSG(is_gtz(a0), "Matrix must be positive definite");
      return nt2::sqrt(a0);
    }
  };

  BOOST_DISPATCH_IMPLEMENT  ( chol_, tag::cpu_
                            , (A0)(A1)(A2)
                            , (scalar_<unspecified_<A0> >)
                              (unspecified_<A1>)
                              (unspecified_<A2>)
                            )
  {
    typedef typename nt2::meta::as_real<A0>::type result_type;

    BOOST_FORCEINLINE result_type operator()(const A0& a0, const A1&, const A2&) const
    {
      BOOST_ASSERT_MSG(is_gtz(a0), "Matrix must be positive definite");
      return nt2::sqrt(a0);
    }
  };
  //============================================================================
  //Cholesky factorization
  //============================================================================
  BOOST_DISPATCH_IMPLEMENT  ( chol_, tag::cpu_
                            , (A0)(N0)(A1)(N1)
                            , ((node_<A0, nt2::tag::chol_
                                    , N0, nt2::container::domain
                                      >
                              ))
                              ((node_<A1, nt2::tag::tie_
                                    , N1, nt2::container::domain
                                     >
                              ))
                            )
  {
    typedef void  result_type;
    typedef typename boost::proto::result_of::child_c<A0&,0>::value_type child0;
    typedef typename child0::value_type                                  type_t;
    typedef nt2::memory::container<tag::table_,  type_t, nt2::_2D>   o_semantic;

    BOOST_FORCEINLINE result_type operator()( A0& a0, A1& a1 ) const
    {
      eval(a0, a1, N0(), N1());
    }

    //==========================================================================
    /// INTERNAL ONLY - R = chol(A)
    BOOST_FORCEINLINE
    void eval ( A0& a0 ,  A1& a1
              , boost::mpl::long_<1> const& , boost::mpl::long_<1> const&
              ) const
    {
      NT2_AS_TERMINAL_INOUT(o_semantic, a
                           , boost::proto::child_c<0>(a0)
                           , boost::proto::child_c<0>(a1));
      NT2_LAPACK_VERIFY(nt2::potrf(boost::proto::value(a),'U'));
      boost::proto::child_c<0>(a1) = nt2::triu(a);
    }

    //==========================================================================
    /// INTERNAL ONLY - L = chol(A,lower_/upper_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<2> const& , boost::mpl::long_<1> const&
              ) const
    {
      eval( a0, a1, N0(), N1()
          , boost::proto::value(boost::proto::child_c<1>(a0))
          );
    }

    //==========================================================================
    /// INTERNAL ONLY - L = chol(A,lower_)
    BOOST_FORCEINLINE
    void eval( A0& a0 , A1& a1
              , boost::mpl::long_<2> const& , boost::mpl::long_<1> const&
              , nt2::policy<ext::lower_> const&
              ) const
    {
      NT2_AS_TERMINAL_INOUT(o_semantic, a
                           , boost::proto::child_c<0>(a0)
                           , boost::proto::child_c<0>(a1));
      NT2_LAPACK_VERIFY(nt2::potrf(boost::proto::value(a),'L'));
      boost::proto::child_c<0>(a1) = nt2::tril(a);
    }

    //==========================================================================
    /// INTERNAL ONLY - R = chol(A,upper_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<2> const& , boost::mpl::long_<1> const&
              , nt2::policy<ext::upper_> const&
              ) const
    {
      eval(a0,a1,boost::mpl::long_<1>(),N1());
    }

    //==========================================================================
    /// INTERNAL ONLY - [R,P] = chol(A)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<1> const& , boost::mpl::long_<2> const&
              ) const
    {
      NT2_AS_TERMINAL_INOUT(o_semantic, a
                           , boost::proto::child_c<0>(a0)
                           , boost::proto::child_c<0>(a1));
      nt2_la_int info = nt2::potrf(boost::proto::value(a),'U');
      BOOST_ASSERT_MSG(info >= 0, "invalid parameter in potrf call");
      if (info == 0)
        boost::proto::child_c<0>(a1) = nt2::triu(a);
      else
        boost::proto::child_c<0>(a1) = nt2::triu(a(nt2::_(1, info-1), nt2::_(1, info-1)));
      boost::proto::child_c<1>(a1) = info;
    }

    //==========================================================================
    /// INTERNAL ONLY - [R,P] = chol(A,lower_/upper_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<2> const& , boost::mpl::long_<2> const&
              ) const
    {
      eval( a0, a1, N0(), N1()
          , boost::proto::value(boost::proto::child_c<1>(a0))
          );
    }

    //==========================================================================
    /// INTERNAL ONLY - L = chol(A, raw_,lower_/upper_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<3> const& , boost::mpl::long_<2> const&
              ) const
    {
      eval( a0, a1, N0(), N1()
          , boost::proto::value(boost::proto::child_c<1>(a0))
          , boost::proto::value(boost::proto::child_c<2>(a0))
          );
    }

    //==========================================================================
    /// INTERNAL ONLY - [L,P] = chol(A,lower_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<2> const& , boost::mpl::long_<2> const&
              , nt2::policy<ext::lower_> const&
              ) const
    {
      NT2_AS_TERMINAL_INOUT(o_semantic, a
                           , boost::proto::child_c<0>(a0)
                           , boost::proto::child_c<0>(a1));
      nt2_la_int info = nt2::potrf(boost::proto::value(a),'L');
      BOOST_ASSERT_MSG(info >= 0, "invalid parameter in potrf call");
      if (info == 0)
        boost::proto::child_c<0>(a1) = nt2::tril(a);
      else
        boost::proto::child_c<0>(a1) = nt2::tril(a(nt2::_(1, info-1), nt2::_(1, info-1)));
      boost::proto::child_c<1>(a1) = info;
    }

    //==========================================================================
    /// INTERNAL ONLY - [R,P] = chol(A,upper_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<2> const& , boost::mpl::long_<2> const&
              , nt2::policy<ext::upper_> const&
              ) const
    {
      eval(a0,a1,
           boost::mpl::long_<1>(),N1());
    }

    //==========================================================================
    /// INTERNAL ONLY - [L,P] = chol(A,raw_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<2> const& , boost::mpl::long_<2> const&
              , nt2::policy<ext::raw_> const&
              ) const
    {
      NT2_AS_TERMINAL_INOUT(o_semantic, a
                           , boost::proto::child_c<0>(a0)
                           , boost::proto::child_c<0>(a1));
      nt2_la_int info = nt2::potrf(boost::proto::value(a),'U');
      BOOST_ASSERT_MSG(info >= 0, "invalid parameter in potrf call");
      assign_swap( boost::proto::child_c<0>(a1), a);
      boost::proto::child_c<1>(a1) = info;
    }

    //==========================================================================
    /// INTERNAL ONLY - [L,P] = chol(A,raw_,lower_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<3> const& , boost::mpl::long_<2> const&
              , nt2::policy<ext::raw_> const&
              , nt2::policy<ext::lower_> const&
              ) const
    {
      NT2_AS_TERMINAL_INOUT(o_semantic, a
                           , boost::proto::child_c<0>(a0)
                           , boost::proto::child_c<0>(a1));
      nt2_la_int info = nt2::potrf(boost::proto::value(a),'L');
      BOOST_ASSERT_MSG(info >= 0, "invalid parameter in potrf call");
      assign_swap( boost::proto::child_c<0>(a1), a);
      boost::proto::child_c<1>(a1) =  info;
    }

    //==========================================================================
    /// INTERNAL ONLY - [L,P] = chol(A,raw_,upper_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<3> const& , boost::mpl::long_<2> const&
              , nt2::policy<ext::raw_> const&
              , nt2::policy<ext::upper_> const&
              ) const
    {
      eval(a0, a1
          , boost::mpl::long_<2>(), N1(), nt2::policy<ext::raw_>());
    }

    //==========================================================================
    /// INTERNAL ONLY - [L,P] = chol(A,upper_,raw_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<3> const& , boost::mpl::long_<2> const&
              , nt2::policy<ext::upper_> const&
              , nt2::policy<ext::raw_> const&
              ) const
    {
      eval(a0, a1
          , boost::mpl::long_<2>(), N1(), nt2::policy<ext::raw_>());
    }

    //==========================================================================
    /// INTERNAL ONLY - [L,P] = chol(A,lower_,raw_)
    BOOST_FORCEINLINE
    void eval ( A0& a0 , A1& a1
              , boost::mpl::long_<3> const& , boost::mpl::long_<2> const&
              , nt2::policy<ext::lower_> const&
              , nt2::policy<ext::raw_> const&
              ) const
    {
      eval(a0, a1
          , boost::mpl::long_<3>(),  boost::mpl::long_<2>()
          , nt2::policy<ext::raw_>(), nt2::policy<ext::lower_>());
    }

  };
} }

#endif


text:
/*****************************************************************************
 *
 * This file is part of Mapnik (c++ mapping toolkit)
 *
 * Copyright (C) 2015 Artem Pavlenko
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 *****************************************************************************/

#include "sqlite.hpp"

// mapnik
#include <mapnik/datasource.hpp>
#include <mapnik/wkb.hpp>
#include <mapnik/feature.hpp>
#include <mapnik/global.hpp>
#include <mapnik/sql_utils.hpp>
#include <mapnik/util/conversions.hpp>
#include <mapnik/geometry_is_empty.hpp>
#include <mapnik/geometry_envelope.hpp>

#include "connection_manager.hpp"
#include "cursorresultset.hpp"

#pragma GCC diagnostic push
#include <mapnik/warning_ignore.hpp>
#include <boost/algorithm/string.hpp>
#pragma GCC diagnostic pop

//st
#include <cstdint>
#include <iostream>
#include <fstream>
#include <memory>

static std::string numeric2string(const char* buf)
{
    std::int16_t ndigits = int2net(buf);
    std::int16_t weight  = int2net(buf+2);
    std::int16_t sign    = int2net(buf+4);
    std::int16_t dscale  = int2net(buf+6);

    const std::unique_ptr<std::int16_t[]> digits(new std::int16_t[ndigits]);
    for (int n=0; n < ndigits ;++n)
    {
        digits[n] = int2net(buf+8+n*2);
    }

    std::ostringstream ss;

    if (sign == 0x4000) ss << "-";

    int i = std::max(weight,std::int16_t(0));
    int d = 0;

    // Each numeric "digit" is actually a value between 0000 and 9999 stored in a 16 bit field.
    // For example, the number 1234567809990001 is stored as four digits: [1234] [5678] [999] [1].
    // Note that the last two digits show that the leading 0's are lost when the number is split.
    // We must be careful to re-insert these 0's when building the string.

    while ( i >= 0)
    {
        if (i <= weight && d < ndigits)
        {
            // All digits after the first must be padded to make the field 4 characters long
            if (d != 0)
            {
#ifdef _WINDOWS
                int dig = digits[d];
                if (dig < 10)
                {
                    ss << "000"; // 0000 - 0009
                }
                else if (dig < 100)
                {
                    ss << "00";  // 0010 - 0099
                }
                else
                {
                    ss << "0";   // 0100 - 0999;
                }
#else
                switch(digits[d])
                {
                case 0 ... 9:
                    ss << "000"; // 0000 - 0009
                    break;
                case 10 ... 99:
                    ss << "00";  // 0010 - 0099
                    break;
                case 100 ... 999:
                    ss << "0";   // 0100 - 0999
                    break;
                }
#endif
            }
            ss << digits[d++];
        }
        else
        {
            if (d == 0)
                ss <<  "0";
            else
                ss <<  "0000";
        }

        i--;
    }
    if (dscale > 0)
    {
        ss << '.';
        // dscale counts the number of decimal digits following the point, not the numeric digits
        while (dscale > 0)
        {
            int value;
            if (i <= weight && d < ndigits)
                value = digits[d++];
            else
                value = 0;

            // Output up to 4 decimal digits for this value
            if (dscale > 0) {
                ss << (value / 1000);
                value %= 1000;
                dscale--;
            }
            if (dscale > 0) {
                ss << (value / 100);
                value %= 100;
                dscale--;
            }
            if (dscale > 0) {
                ss << (value / 10);
                value %= 10;
                dscale--;
            }
            if (dscale > 0) {
                ss << value;
                dscale--;
            }

            i--;
        }
    }
    return ss.str();
}

namespace mapnik {

template <typename Connection>
void pgsql2sqlite(Connection conn,
                  std::string const& query,
                  std::string const& output_table_name,
                  std::string const& output_filename)
{
    namespace sqlite = mapnik::sqlite;
    sqlite::database db(output_filename);

    std::shared_ptr<ResultSet> rs = conn->executeQuery("select * from (" + query + ") as query limit 0;");
    int count = rs->getNumFields();

    std::ostringstream select_sql;

    select_sql << "select ";

    for (int i=0; i<count; ++i)
    {
        if (i!=0) select_sql << ",";
        select_sql << "\"" <<  rs->getFieldName(i) << "\"";
    }

    select_sql << " from (" << query << ") as query";

    std::string table_name = mapnik::sql_utils::table_from_sql(query);

    std::string schema_name="";
    std::string::size_type idx=table_name.find_last_of('.');
    if (idx!=std::string::npos)
    {
        schema_name=table_name.substr(0,idx);
        table_name=table_name.substr(idx+1);
    }
    else
    {
        table_name=table_name.substr(0);
    }

    std::ostringstream geom_col_sql;
    geom_col_sql << "select f_geometry_column,srid,type from geometry_columns ";
    geom_col_sql << "where f_table_name='" << table_name << "'";
    if (schema_name.length() > 0)
    {
        geom_col_sql <<" and f_table_schema='"<< schema_name <<"'";
    }

    rs = conn->executeQuery(geom_col_sql.str());

    int srid = -1;
    std::string geom_col = "UNKNOWN";
    std::string geom_type = "UNKNOWN";

    if ( rs->next())
    {
        if (!mapnik::util::string2int(rs->getValue("srid"),srid))
        {
            std::clog << "could not convert srid to integer\n";
        }
        geom_col = rs->getValue("f_geometry_column");
        geom_type = rs->getValue("type");
    }

    // add AsBinary(<geometry_column>) modifier
    std::string select_sql_str = select_sql.str();
    boost::algorithm::replace_all(select_sql_str, "\"" + geom_col + "\"","ST_AsBinary(" + geom_col+") as " + geom_col);

#ifdef MAPNIK_DEBUG
    std::cout << select_sql_str << "\n";
#endif

    std::ostringstream cursor_sql;
    std::string cursor_name("my_cursor");

    cursor_sql << "DECLARE " << cursor_name << " BINARY INSENSITIVE NO SCROLL CURSOR WITH HOLD FOR " << select_sql_str << " FOR READ ONLY";
    conn->execute(cursor_sql.str());

    std::shared_ptr<CursorResultSet> cursor(new CursorResultSet(conn,cursor_name,10000));

    unsigned num_fields = cursor->getNumFields();

    if (num_fields == 0) return;

    std::string feature_id =  "fid";

    std::ostringstream create_sql;
    create_sql << "create table if not exists " << output_table_name << " (" << feature_id << " INTEGER PRIMARY KEY AUTOINCREMENT,";

    int geometry_oid = -1;

    std::string output_table_insert_sql = "insert into " + output_table_name + " values (?";

    context_ptr ctx = std::make_shared<context_type>();

    for ( unsigned pos = 0; pos < num_fields ; ++pos)
    {
        const char* field_name = cursor->getFieldName(pos);
        ctx->push(field_name);

        if (pos > 0)
        {
            create_sql << ",";
        }
        output_table_insert_sql +=",?";
        int oid = cursor->getTypeOID(pos);
        if (geom_col == cursor->getFieldName(pos))
        {
            geometry_oid = oid;
            create_sql << "'" << cursor->getFieldName(pos) << "' BLOB";
        }
        else
        {
            create_sql << "'" << cursor->getFieldName(pos);
            switch (oid)
            {
            case 20:
            case 21:
            case 23:
                create_sql << "' INTEGER";
                break;
            case 700:
            case 701:
                create_sql << "' REAL";
                break;
            default:
                create_sql << "' TEXT";
                break;
            }

        }
    }

    create_sql << ");";
    output_table_insert_sql +=")";

    std::cout << "client_encoding=" << conn->client_encoding() << "\n";
    std::cout << "geometry_column=" << geom_col << "(" << geom_type
              <<  ") srid=" << srid << " oid=" << geometry_oid << "\n";

    db.execute("begin;");
    // output table sql
    db.execute(create_sql.str());

    // spatial index sql
    std::string spatial_index_sql = "create virtual table idx_" + output_table_name
        + "_" + geom_col + " using rtree(pkid, xmin, xmax, ymin, ymax)";

    db.execute(spatial_index_sql);

    //blob_to_hex hex;
    int pkid = 0;

    std::string spatial_index_insert_sql = "insert into idx_" + output_table_name +  "_"
        +  geom_col + " values (?,?,?,?,?)" ;

    sqlite::prepared_statement spatial_index(db,spatial_index_insert_sql);

#ifdef MAPNIK_DEBUG
    std::cout << output_table_insert_sql << "\n";
#endif

    sqlite::prepared_statement output_table(db,output_table_insert_sql);

    while (cursor->next())
    {
        ++pkid;

        sqlite::record_type output_rec;
        output_rec.push_back(sqlite::value_type(pkid));
        bool empty_geom = true;
        const char * buf = 0;
        for (unsigned pos=0 ; pos < num_fields; ++pos)
        {
            if (! cursor->isNull(pos))
            {
                int size=cursor->getFieldLength(pos);
                int oid = cursor->getTypeOID(pos);
                buf=cursor->getValue(pos);

                switch (oid)
                {
                case 25:
                case 1042:
                case 1043:
                {
                    std::string text(buf);
                    boost::algorithm::replace_all(text,"'","''");
                    output_rec.push_back(sqlite::value_type(text));
                    break;
                }
                case 23:
                    output_rec.emplace_back(int4net(buf));
                    break;
                case 21:
                    output_rec.emplace_back(int(int2net(buf)));
                    break;
                case 700:
                {
                    float val;
                    float4net(val,buf);
                    output_rec.emplace_back(double(val));
                    break;
                }
                case 701:
                {
                    double val;
                    float8net(val,buf);
                    output_rec.emplace_back(val);
                    break;
                }
                case 1700:
                {
                    std::string str = numeric2string(buf);
                    double val;
                    if (mapnik::util::string2double(str,val))
                    {
                        output_rec.emplace_back(val);
                    }
                    break;
                }

                default:
                {
                    if (oid == geometry_oid)
                    {
                        mapnik::feature_impl feat(ctx,pkid);
                        mapnik::geometry::geometry<double> geom = geometry_utils::from_wkb(buf, size, wkbGeneric);
                        if (!mapnik::geometry::is_empty(geom))
                        {
                            box2d<double> bbox = mapnik::geometry::envelope(geom);
                            if (bbox.valid())
                            {
                                sqlite::record_type rec;
                                rec.push_back(sqlite::value_type(pkid));
                                rec.push_back(sqlite::value_type(bbox.minx()));
                                rec.push_back(sqlite::value_type(bbox.maxx()));
                                rec.push_back(sqlite::value_type(bbox.miny()));
                                rec.push_back(sqlite::value_type(bbox.maxy()));
                                spatial_index.insert_record(rec);
                                empty_geom = false;
                            }
                        }
                        output_rec.push_back(sqlite::blob(buf,size));
                    }
                    else
                    {
                        output_rec.push_back(sqlite::null_type());
                    }
                    break;
                }
                }
            }
            else
            {
                output_rec.push_back(sqlite::null_type());
            }
        }

        if (!empty_geom) output_table.insert_record(output_rec);

        if (pkid % 1000 == 0)
        {
            std::cout << "\r processing " << pkid << " features";
            std::cout.flush();
        }

        if (pkid % 100000 == 0)
        {
            db.execute("commit;begin;");
        }
    }
    // commit
    db.execute("commit;");
    std::cout << "\r processed " << pkid << " features";
    db.execute("VACUUM;");
    std::cout << "\r vacumming";
    std::cout << "\n Done!" << std::endl;
}
}


text:
#pragma once
#include <graphene/chain/protocol/operations.hpp>
#include <graphene/db/generic_index.hpp>
#include <boost/multi_index/composite_key.hpp>
#include <graphene/chain/contract_entry.hpp>
#include <graphene/chain/vesting_balance_object.hpp>
#include <vector>
namespace graphene {
    namespace chain {

        struct by_contract_id;

		struct by_contract_name {};
        class contract_object : public abstract_object<contract_object> {
        public:
            static const uint8_t space_id = protocol_ids;
            static const uint8_t type_id = contract_object_type;
            uint32_t  registered_block;
            uvm::blockchain::Code code;
            address owner_address;
            time_point_sec create_time;
            string name;
            contract_address_type contract_address;
			string contract_name;
			string contract_desc;
            contract_type type_of_contract = normal_contract;
			string native_contract_key; // key to find native contract code
            vector<contract_address_type> derived;
            contract_address_type inherit_from;

        };
        struct by_owner{};
        struct by_contract_obj_id {};
        struct by_registered_block {};
        typedef multi_index_container<
            contract_object,
            indexed_by<
            ordered_unique<tag<by_id>, member<object, object_id_type, &object::id>>,
            ordered_unique<tag<by_contract_id>, member<contract_object, contract_address_type, &contract_object::contract_address>>,
			ordered_non_unique<tag<by_contract_name>, member<contract_object, string, &contract_object::contract_name>>,
            ordered_non_unique<tag<by_owner>, member<contract_object, address, &contract_object::owner_address>>,
            ordered_non_unique<tag<by_registered_block>, member<contract_object, uint32_t, &contract_object::registered_block>>
            >> contract_object_multi_index_type;
        typedef generic_index<contract_object, contract_object_multi_index_type> contract_object_index;
        class contract_storage_change_object : public abstract_object<contract_storage_change_object> {
        public:
            static const uint8_t space_id = protocol_ids;
            static const uint8_t type_id = contract_storage_change_object_type;
            contract_address_type contract_address;
            uint32_t block_num;
        };

        struct by_block_num {};
        typedef multi_index_container<
            contract_storage_change_object,
        indexed_by<
            ordered_unique<tag<by_id>, member<object, object_id_type, &object::id>>,
            ordered_unique<tag<by_contract_id>, member<contract_storage_change_object, contract_address_type, &contract_storage_change_object::contract_address>>,
            ordered_non_unique<tag<by_block_num>, member<contract_storage_change_object, uint32_t, &contract_storage_change_object::block_num>>
        >> contract_storage_change_object_multi_index_type;

        typedef generic_index<contract_storage_change_object, contract_storage_change_object_multi_index_type> contract_storage_change_index;
		class contract_storage_object : public abstract_object<contract_storage_object> {
		public:
			static const uint8_t space_id = protocol_ids;
			static const uint8_t type_id = contract_storage_object_type;

            contract_address_type contract_address;
			string storage_name;
			std::vector<char> storage_value;
		};
		struct by_contract_id_storage_name {};
		typedef multi_index_container<
			contract_storage_object,
			indexed_by<
			ordered_unique<tag<by_id>, member<object, object_id_type, &object::id>>,
			ordered_unique< tag<by_contract_id_storage_name>,
			composite_key<
			contract_storage_object,
			member<contract_storage_object, contract_address_type, &contract_storage_object::contract_address>,
			member<contract_storage_object, string, &contract_storage_object::storage_name>
			>
			>
			>> contract_storage_object_multi_index_type;
		typedef generic_index<contract_storage_object, contract_storage_object_multi_index_type> contract_storage_object_index;

        class contract_balance_object : public abstract_object<contract_balance_object>
        {
        public:
            static const uint8_t space_id = protocol_ids;
            static const uint8_t type_id = contract_balance_object_type;

            bool is_vesting_balance()const
            {
                return vesting_policy.valid();
            }
            asset available(fc::time_point_sec now)const
            {
                return is_vesting_balance() ? vesting_policy->get_allowed_withdraw({ balance, now,{} })
                    : balance;
            }
            void adjust_balance(asset delta, fc::time_point_sec now)
            {
                balance += delta;
                last_claim_date = now;
            }
            contract_address_type owner;
            asset   balance;
            optional<linear_vesting_policy> vesting_policy;
            time_point_sec last_claim_date;
            asset_id_type asset_type()const { return balance.asset_id; }
        };

        struct by_owner;

        /**
        * @ingroup object_index
        */
        using contract_balance_multi_index_type = multi_index_container<
            contract_balance_object,
            indexed_by<
            ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
			ordered_non_unique< tag<by_contract_id>, member< contract_balance_object, contract_address_type, &contract_balance_object::owner > >,
            ordered_non_unique< tag<by_owner>, composite_key<
            contract_balance_object,
            member<contract_balance_object, contract_address_type, &contract_balance_object::owner>,
            const_mem_fun<contract_balance_object, asset_id_type, &contract_balance_object::asset_type>
            > >
            >
        >;

        /**
        * @ingroup object_index
        */
        using contract_balance_index = generic_index<contract_balance_object, contract_balance_multi_index_type>;

		class contract_event_notify_object : public abstract_object<contract_event_notify_object>
		{
		public:
			static const uint8_t space_id = protocol_ids;
			static const uint8_t type_id = contract_event_notify_object_type;

            contract_address_type contract_address;
			string event_name;
			string event_arg;
			transaction_id_type trx_id;
            uint64_t block_num;
            uint64_t op_num;
		};

		using contract_event_notify_multi_index_type = multi_index_container<
			contract_event_notify_object,
			indexed_by<
			ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
			ordered_non_unique<tag<by_contract_id>, member<contract_event_notify_object, contract_address_type, &contract_event_notify_object::contract_address>>
			>
		>;
		using contract_event_notify_index = generic_index<contract_event_notify_object, contract_event_notify_multi_index_type>;

        class contract_invoke_result_object : public abstract_object<contract_invoke_result_object>
        {
        public:
            static const uint8_t space_id = protocol_ids;
            static const uint8_t type_id = contract_invoke_result_object_type;
            transaction_id_type trx_id;
            uint32_t block_num;
            int op_num;
            std::string api_result;
            std::vector<contract_event_notify_info> events;
            bool exec_succeed = true;
            share_type acctual_fee;
            address invoker;
            std::map<std::string, contract_storage_changes_type, comparator_for_string> storage_changes;

           std::map<std::pair<contract_address_type, asset_id_type>, share_type> contract_withdraw;
           std::map<std::pair<contract_address_type, asset_id_type>, share_type> contract_balances;
           std::map<std::pair<address, asset_id_type>, share_type> deposit_to_address;
           std::map<std::pair<contract_address_type, asset_id_type>, share_type> deposit_contract;

            inline bool operator<(const contract_invoke_result_object& obj) const
            {
                if (block_num < obj.block_num)
                    return true;
                if(block_num == obj.block_num)
                    return op_num < obj.op_num;
                return false;
            }
        };
        struct by_trxid_and_opnum {};
        struct by_trxid {};
        using contract_invoke_result_multi_index_type = multi_index_container <
            contract_invoke_result_object,
            indexed_by <
            ordered_unique< tag<by_id>, member< object, object_id_type, &object::id > >,
            ordered_non_unique<tag<by_trxid>, member<contract_invoke_result_object, transaction_id_type, &contract_invoke_result_object::trx_id>>,
            ordered_unique<tag<by_trxid_and_opnum>,
            composite_key<contract_invoke_result_object,
                member<contract_invoke_result_object, transaction_id_type, &contract_invoke_result_object::trx_id>,
                member<contract_invoke_result_object, int, &contract_invoke_result_object::op_num>>>
            >
        >;
        using contract_invoke_result_index = generic_index<contract_invoke_result_object, contract_invoke_result_multi_index_type>;
        class contract_hash_entry
        {
        public:
            std::string contract_address;
            std::string hash;
        public:
            contract_hash_entry() {}
            inline contract_hash_entry(const chain::contract_object& cont)
            {
                contract_address = cont.contract_address.operator fc::string();
                hash = cont.code.GetHash();
            }
        };
    }

}
FC_REFLECT_DERIVED(graphene::chain::contract_object, (graphene::db::object),
    (registered_block)(code)(owner_address)(create_time)(name)(contract_address)(type_of_contract)(native_contract_key)(contract_name)(contract_desc)(derived)(inherit_from))
FC_REFLECT_DERIVED(graphene::chain::contract_storage_object, (graphene::db::object),
	(contract_address)(storage_name)(storage_value))
FC_REFLECT_DERIVED(graphene::chain::contract_balance_object, (graphene::db::object),
    (owner)(balance)(vesting_policy)(last_claim_date))
FC_REFLECT_DERIVED(graphene::chain::contract_event_notify_object, (graphene::db::object),
	(contract_address)(event_name)(event_arg)(trx_id)(block_num)(op_num))
FC_REFLECT_DERIVED(graphene::chain::contract_invoke_result_object, (graphene::db::object),
    (trx_id)(block_num)(op_num)(api_result)(events)(exec_succeed)(acctual_fee)(invoker)(contract_withdraw)(contract_balances)(deposit_to_address)(deposit_contract))
    //(contract_withdraw)(contract_balances)(deposit_to_address)(deposit_contract)
FC_REFLECT(graphene::chain::contract_hash_entry,(contract_address)(hash))

FC_REFLECT_DERIVED(graphene::chain::contract_storage_change_object, (graphene::db::object),(contract_address)(block_num))

max_stars_repo_name: BlockLink/HX-core

max_issues_repo_name: BlockLink/HX-core

max_forks_repo_name: BlockLink/HX-core


text:
/**************************************************************
 *
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 *
 *************************************************************/

#ifndef INCLUDED_TBLSTYLEPRHANDLER_HXX
#define INCLUDED_TBLSTYLEPRHANDLER_HXX

#include "TablePropertiesHandler.hxx"

#include <dmapper/DomainMapper.hxx>
#include <WriterFilterDllApi.hxx>
#include <resourcemodel/LoggedResources.hxx>
#include <boost/shared_ptr.hpp>

namespace writerfilter {
namespace dmapper {

class DomainMapper;
class PropertyMap;

enum TblStyleType
{
    TBL_STYLE_UNKNOWN,
    TBL_STYLE_WHOLETABLE,
    TBL_STYLE_FIRSTROW,
    TBL_STYLE_LASTROW,
    TBL_STYLE_FIRSTCOL,
    TBL_STYLE_LASTCOL,
    TBL_STYLE_BAND1VERT,
    TBL_STYLE_BAND2VERT,
    TBL_STYLE_BAND1HORZ,
    TBL_STYLE_BAND2HORZ,
    TBL_STYLE_NECELL,
    TBL_STYLE_NWCELL,
    TBL_STYLE_SECELL,
    TBL_STYLE_SWCELL
};

class WRITERFILTER_DLLPRIVATE TblStylePrHandler : public LoggedProperties
{
private:
    DomainMapper &              m_rDMapper;
    TablePropertiesHandler *    m_pTablePropsHandler;

    TblStyleType                m_nType;
    PropertyMapPtr              m_pProperties;

    // Properties
    virtual void lcl_attribute(Id Name, Value & val);
    virtual void lcl_sprm(Sprm & sprm);

public:
    TblStylePrHandler( DomainMapper & rDMapper );
    virtual ~TblStylePrHandler( );

    inline PropertyMapPtr       getProperties() { return m_pProperties; };
    inline TblStyleType         getType() { return m_nType; };

private:

    void resolveSprmProps(Sprm & rSprm);
};

typedef boost::shared_ptr< TblStylePrHandler > TblStylePrHandlerPtr;

}}

#endif

ext: hxx

max_stars_repo_name: Grosskopf/openoffice

max_issues_repo_name: Grosskopf/openoffice

max_forks_repo_name: Grosskopf/openoffice


text:
/////////1/////////2/////////3/////////4/////////5/////////6/////////7/////////8
// test_iterators.cpp

// (C) Copyright 2002 Robert Ramey - http://www.rrsd.com .
// Use, modification and distribution is subject to the Boost Software
// License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)

#include <algorithm> // std::copy
#include <vector>
#include <cstdlib> // for rand
#include <functional>
#include <sstream> // used to test stream iterators

#include <boost/config.hpp>
#ifdef BOOST_NO_STDC_NAMESPACE
namespace std{
    using ::rand;
}
#endif

#include <boost/detail/workaround.hpp>
#if BOOST_WORKAROUND(BOOST_DINKUMWARE_STDLIB, == 1)
#include <boost/archive/dinkumware.hpp>
#endif

#ifndef BOOST_NO_CWCHAR
#include <boost/archive/iterators/mb_from_wchar.hpp>
#include <boost/archive/iterators/wchar_from_mb.hpp>
#endif
#include <boost/archive/iterators/xml_escape.hpp>
#include <boost/archive/iterators/xml_unescape.hpp>
#include <boost/archive/iterators/transform_width.hpp>
#include <boost/archive/iterators/istream_iterator.hpp>
#include <boost/archive/iterators/ostream_iterator.hpp>

#include "test_tools.hpp"

#ifndef BOOST_NO_CWCHAR

void test_wchar_from_mb(const wchar_t *la, const char * a, const unsigned int size){
    typedef boost::archive::iterators::wchar_from_mb<const char *> translator;
    BOOST_CHECK((
        std::equal(
            translator(a),
            translator(a + size),
            la
        )
    ));
}

void test_mb_from_wchar(const char * a, const wchar_t *la, const unsigned int size){
    typedef boost::archive::iterators::mb_from_wchar<const wchar_t *> translator;
    BOOST_CHECK(
        std::equal(
            translator(la),
            translator(la + size),
            a
        )
    );
}

#endif

template<class CharType>
void test_xml_escape(
    const CharType * xml_escaped,
    const CharType * xml,
    unsigned int size
){
    typedef boost::archive::iterators::xml_escape<const CharType *> translator;

    BOOST_CHECK(
        std::equal(
            translator(xml),
            translator(xml + size),
            xml_escaped
        )
    );
}

template<class CharType>
void test_xml_unescape(
    const CharType * xml,
    const CharType * xml_escaped,
    unsigned int size
){

    // test xml_unescape
    typedef boost::archive::iterators::xml_unescape<const CharType *> translator;

    BOOST_CHECK(
        std::equal(
            translator(xml_escaped),
            translator(xml_escaped + size),
            xml
        )
    );
}

template<int BitsOut, int BitsIn>
void test_transform_width(unsigned int size){
    // test transform_width
    char rawdata[8];

    char * rptr;
    for(rptr = rawdata + size; rptr-- > rawdata;)
        *rptr = static_cast<char>(0xff & std::rand());

    // convert 8 to 6 bit characters
    typedef boost::archive::iterators::transform_width<
        char *, BitsOut, BitsIn
    > translator1;

    std::vector<char> vout;

    std::copy(
        translator1(static_cast<char *>(rawdata)),
        translator1(rawdata + size),
        std::back_inserter(vout)
    );

    // check to see we got the expected # of characters out
    if(0 ==  size)
        BOOST_CHECK(vout.size() == 0);
    else
        BOOST_CHECK(vout.size() == (size * BitsIn - 1 ) / BitsOut + 1);

    typedef boost::archive::iterators::transform_width<
        std::vector<char>::iterator, BitsIn, BitsOut
    > translator2;

    std::vector<char> vin;
    std::copy(
        translator2(vout.begin()),
        translator2(vout.end()),
        std::back_inserter(vin)
    );

    // check to see we got the expected # of characters out
    BOOST_CHECK(vin.size() == size);

    BOOST_CHECK(
        std::equal(
            rawdata,
            rawdata + size,
            vin.begin()
        )
    );
}

template<class CharType>
void test_stream_iterators(
    const CharType * test_data,
    unsigned int size
){
    std::basic_stringstream<CharType> ss;
    boost::archive::iterators::ostream_iterator<CharType> osi =
        boost::archive::iterators::ostream_iterator<CharType>(ss);
    std::copy(test_data, test_data + size, osi);

    BOOST_CHECK(size == ss.str().size());

    boost::archive::iterators::istream_iterator<CharType> isi =
        boost::archive::iterators::istream_iterator<CharType>(ss);
    BOOST_CHECK(std::equal(test_data, test_data + size,isi));
}

int
test_main(int /* argc */, char* /* argv */ [] )
{
    const char xml[] = "<+>+&+\"+'";
    const char xml_escaped[] = "<+>+&+"+'";
    test_xml_escape<const char>(
        xml_escaped,
        xml,
        sizeof(xml) / sizeof(char) - 1
    );
    test_xml_unescape<const char>(
        xml,
        xml_escaped,
        sizeof(xml_escaped) / sizeof(char) - 1
    );

    const char a[] = "abcdefghijklmnopqrstuvwxyz";

    #ifndef BOOST_NO_CWCHAR
    const wchar_t wxml[] = L"<+>+&+\"+'";
    const wchar_t wxml_escaped[] = L"<+>+&+"+'";
    test_xml_escape<const wchar_t>(
        wxml_escaped,
        wxml,
        sizeof(wxml) / sizeof(wchar_t) - 1
    );
    test_xml_unescape<const wchar_t>(
        wxml,
        wxml_escaped,
        sizeof(wxml_escaped) / sizeof(wchar_t) - 1
    );

    const wchar_t la[] = L"abcdefghijklmnopqrstuvwxyz";

    test_wchar_from_mb(la, a, sizeof(a) / sizeof(char) - 1);
    test_mb_from_wchar(a, la, sizeof(la) / sizeof(wchar_t) - 1);

    test_stream_iterators<wchar_t>(la, sizeof(la)/sizeof(wchar_t) - 1);
    #endif

    test_stream_iterators<char>(a, sizeof(a) - 1);

    test_transform_width<6, 8>(0);
    test_transform_width<6, 8>(1);
    test_transform_width<6, 8>(2);
    test_transform_width<6, 8>(3);
    test_transform_width<6, 8>(4);
    test_transform_width<6, 8>(5);
    test_transform_width<6, 8>(6);
    test_transform_width<6, 8>(7);
    test_transform_width<6, 8>(8);

    return EXIT_SUCCESS;
}

max_stars_repo_name: fineshift/boost

max_issues_repo_name: fineshift/boost

max_forks_repo_name: fineshift/boost


text:
#ifndef CDPI_STREAM_HPP
#define CDPI_STREAM_HPP

#include "cdpi_bytes.hpp"
#include "cdpi_event.hpp"
#include "cdpi_id.hpp"
#include "cdpi_proto.hpp"

#include <list>
#include <map>
#include <sstream>

#include <boost/shared_ptr.hpp>

#define PROTO_TO_HTTP(PROTO) boost::dynamic_pointer_cast<cdpi_http>(PROTO)
#define PROTO_TO_SSL(PROTO)  boost::dynamic_pointer_cast<cdpi_ssl>(PROTO)

enum cdpi_stream_event {
    STREAM_CREATED,
    STREAM_DATA_IN,
    STREAM_DESTROYED,
    STREAM_ERROR,
};

struct cdpi_stream_info {
    std::list<cdpi_bytes>     m_bytes;
    std::list<ptr_cdpi_proto> m_proxy;
    cdpi_proto_type           m_type;
    ptr_cdpi_proto            m_proto;
    uint64_t                  m_total_size;
    time_t                    m_init_time;
    bool                      m_is_gaveup;

    cdpi_stream_info() : m_type(PROTO_NONE), m_total_size(0),
                         m_init_time(time(NULL)), m_is_gaveup(false) { }
};

class cdpi_parse_error {
public:
    cdpi_parse_error(std::string file, int line) {
        std::stringstream ss;

        ss << file << ":" << line;

        m_msg = ss.str();
    }

    std::string m_msg;
};

class cdpi_proxy { };

typedef boost::shared_ptr<cdpi_stream_info> ptr_cdpi_stream_info;

class cdpi_event_listener;
typedef boost::shared_ptr<cdpi_event_listener> ptr_cdpi_event_listener;

class cdpi_stream {
public:
    cdpi_stream();
    virtual ~cdpi_stream();

    void in_stream_event(cdpi_stream_event st_event, const cdpi_id_dir &id_dir,
                         cdpi_bytes bytes);

    void set_event_listener(ptr_cdpi_event_listener &listener) {
        m_listener = listener;
    }

    uint64_t get_sent_bytes(cdpi_id_dir id_dir);
    double get_bps(cdpi_id_dir id_dir);

    ptr_cdpi_proto get_proto(cdpi_id_dir id_dir);

private:
    std::map<cdpi_id_dir, ptr_cdpi_stream_info> m_info;

    void create_stream(const cdpi_id_dir &id_dir);
    void destroy_stream(const cdpi_id_dir &id_dir);
    void in_data(const cdpi_id_dir &id_dir, cdpi_bytes bytes);

    ptr_cdpi_event_listener m_listener;

};

#endif // CDPI_STREAM_HPP


text:
//==============================================================================
//         Copyright 2003 - 2012   LASMEA UMR 6602 CNRS/Univ. Clermont II
//         Copyright 2009 - 2012   LRI    UMR 8623 CNRS/Univ Paris Sud XI
//
//          Distributed under the Boost Software License, Version 1.0.
//                 See accompanying file LICENSE.txt or copy at
//                     http://www.boost.org/LICENSE_1_0.txt
//==============================================================================
#ifndef BOOST_SIMD_INCLUDE_FUNCTOR_HPP_INCLUDED
#define BOOST_SIMD_INCLUDE_FUNCTOR_HPP_INCLUDED

#include <boost/simd/sdk/config/types.hpp>
#include <boost/simd/sdk/simd/extensions.hpp>
#include <boost/simd/sdk/simd/native_fwd.hpp>
#include <boost/simd/sdk/simd/category.hpp>
#include <boost/dispatch/include/functor.hpp>
#include <boost/dispatch/dsl/call.hpp>
#include <boost/simd/sdk/functor/preprocessor/function.hpp>
#include <boost/simd/sdk/functor/preprocessor/call.hpp>

namespace boost { namespace dispatch
{
  template<class Tag, class Site>
  struct generic_dispatcher
  {
    /* While ICC supports SFINAE with decltype, it seems to cause
     * infinite compilation times in some cases */
    #if defined(BOOST_NO_SFINAE_EXPR) || defined(__INTEL_COMPILER)
    /*! For compatibility with result_of protocol */
    template<class Sig>
    struct result;

    // result_of needs to SFINAE in this case
    template<class This, class... Args>
    struct result<This(Args...)>
         : boost::dispatch::meta::
           result_of< decltype(dispatching(meta::adl_helper(), Tag(), boost::dispatch::default_site_t<Site>(), boost::dispatch::meta::hierarchy_of_t<Args>()...))(Args...) >
    {
    };

    template<class... Args>
    BOOST_FORCEINLINE typename result<generic_dispatcher(Args&&...)>::type
    operator()(Args&&... args) const
    {
      return dispatching(meta::adl_helper(), Tag(), boost::dispatch::default_site_t<Site>(), boost::dispatch::meta::hierarchy_of_t<Args&&>()...)(static_cast<Args&&>(args)...);
    }
    #else
    template<class... Args>
    BOOST_FORCEINLINE auto
    operator()(Args&&... args) const
    BOOST_AUTO_DECLTYPE_BODY_SFINAE(
      dispatching(meta::adl_helper(), Tag(), boost::dispatch::default_site_t<Site>(), boost::dispatch::meta::hierarchy_of_t<Args&&>()...)(static_cast<Args&&>(args)...)
    )
    #endif
  };
} }

namespace boost { namespace simd { namespace ext
{
  struct adl_helper {};

  template<class Tag, class Site>
  BOOST_FORCEINLINE boost::dispatch::generic_dispatcher<Tag, Site>
  dispatching(adl_helper, unknown_<Tag>, unknown_<Site>, ...)
  {
    return boost::dispatch::generic_dispatcher<Tag, Site>();
  }
} } }

namespace boost { namespace simd
{
  template<class Tag, class Site>
  struct generic_dispatcher
  {
    /* While ICC supports SFINAE with decltype, it seems to cause
     * infinite compilation times in some cases */
    #if defined(BOOST_NO_SFINAE_EXPR) || defined(__INTEL_COMPILER)
    /*! For compatibility with result_of protocol */
    template<class Sig>
    struct result;

    // result_of needs to SFINAE in this case
    template<class This, class... Args>
    struct result<This(Args...)>
         : boost::dispatch::meta::
           result_of< decltype(dispatching(ext::adl_helper(), Tag(), boost::dispatch::default_site_t<Site>(), boost::dispatch::meta::hierarchy_of_t<Args>()...))(Args...) >
    {
    };

    template<class... Args>
    BOOST_FORCEINLINE typename result<generic_dispatcher(Args&&...)>::type
    operator()(Args&&... args) const
    {
      return dispatching(ext::adl_helper(), Tag(), boost::dispatch::default_site_t<Site>(), boost::dispatch::meta::hierarchy_of_t<Args&&>()...)(static_cast<Args&&>(args)...);
    }
    #else
    template<class... Args>
    BOOST_FORCEINLINE auto
    operator()(Args&&... args) const
    BOOST_AUTO_DECLTYPE_BODY_SFINAE(
      dispatching(ext::adl_helper(), Tag(), boost::dispatch::default_site_t<Site>(), boost::dispatch::meta::hierarchy_of_t<Args&&>()...)(static_cast<Args&&>(args)...)
    )
    #endif
  };
} }

#endif


text:
/*
   Copyright (c) Marshall Clow 2011-2012.

   Distributed under the Boost Software License, Version 1.0. (See accompanying
   file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)

    For more information, see http://www.boost.org
*/

#include <iostream>

#include <boost/config.hpp>
#include <boost/algorithm/cxx11/is_permutation.hpp>

#define BOOST_TEST_MAIN
#include <boost/test/unit_test.hpp>

#include <string>
#include <vector>
#include <list>

namespace ba = boost::algorithm;
// namespace ba = boost;

void test_sequence1 () {
    std::vector<int> v, v1;

    v.clear ();
    for ( std::size_t i = 5; i < 15; ++i )
        v.push_back ( i );
    v1 = v;
    BOOST_CHECK ( ba::is_permutation ( v.begin (), v.end (), v.begin ()));  // better be a permutation of itself!
    BOOST_CHECK ( ba::is_permutation ( v.begin (), v.end (), v1.begin ()));

//  With bidirectional iterators.
    std::list<int> l;
    std::copy ( v.begin (), v.end (), std::back_inserter ( l ));
    BOOST_CHECK ( ba::is_permutation ( l.begin (), l.end (), l.begin ()));  // better be a permutation of itself!
    BOOST_CHECK ( ba::is_permutation ( l.begin (), l.end (), v1.begin ()));
    for ( std::size_t i = 0; i < l.size (); ++i ) {
        l.push_back ( *l.begin ()); l.pop_front (); // rotation
        BOOST_CHECK ( ba::is_permutation ( l.begin (), l.end (), v1.begin ()));
        }
    }

BOOST_AUTO_TEST_CASE( test_main )
{
  test_sequence1 ();
}

max_stars_repo_name: smart-make/boost

max_issues_repo_name: smart-make/boost

max_forks_repo_name: smart-make/boost


text:
//
// Copyright (c) 2016-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Official repository: https://github.com/boostorg/beast
//

#ifndef BOOST_BEAST_DETAIL_BIND_HANDLER_HPP
#define BOOST_BEAST_DETAIL_BIND_HANDLER_HPP

#include <boost/beast/core/error.hpp>
#include <boost/beast/core/detail/tuple.hpp>
#include <boost/asio/associated_allocator.hpp>
#include <boost/asio/associated_executor.hpp>
#include <boost/asio/handler_alloc_hook.hpp>
#include <boost/asio/handler_continuation_hook.hpp>
#include <boost/asio/handler_invoke_hook.hpp>
#include <boost/core/ignore_unused.hpp>
#include <boost/mp11/integer_sequence.hpp>
#include <boost/is_placeholder.hpp>
#include <functional>
#include <type_traits>
#include <utility>

namespace boost {
namespace beast {
namespace detail {

//------------------------------------------------------------------------------
//
// bind_handler
//
//------------------------------------------------------------------------------

template<class Handler, class... Args>
class bind_wrapper
{
    using args_type = detail::tuple<Args...>;

    Handler h_;
    args_type args_;

    template<class T, class Executor>
    friend struct net::associated_executor;

    template<class Arg, class Vals>
    static
    typename std::enable_if<
        std::is_placeholder<typename
            std::decay<Arg>::type>::value == 0 &&
        boost::is_placeholder<typename
            std::decay<Arg>::type>::value == 0,
        Arg&&>::type
    extract(Arg&& arg, Vals&& vals)
    {
        boost::ignore_unused(vals);
        return std::forward<Arg>(arg);
    }

    template<class Arg, class Vals>
    static
    typename std::enable_if<
        std::is_placeholder<typename
            std::decay<Arg>::type>::value != 0,
        tuple_element<std::is_placeholder<
            typename std::decay<Arg>::type>::value - 1,
        Vals>>::type&&
    extract(Arg&&, Vals&& vals)
    {
        return detail::get<std::is_placeholder<
            typename std::decay<Arg>::type>::value - 1>(
                std::forward<Vals>(vals));
    }

    template<class Arg, class Vals>
    static
    typename std::enable_if<
        boost::is_placeholder<typename
            std::decay<Arg>::type>::value != 0,
        tuple_element<boost::is_placeholder<
            typename std::decay<Arg>::type>::value - 1,
        Vals>>::type&&
    extract(Arg&&, Vals&& vals)
    {
        return detail::get<boost::is_placeholder<
            typename std::decay<Arg>::type>::value - 1>(
                std::forward<Vals>(vals));
    }

    template<class ArgsTuple, std::size_t... S>
    static
    void
    invoke(
        Handler& h,
        ArgsTuple& args,
        tuple<>&&,
        mp11::index_sequence<S...>)
    {
        boost::ignore_unused(args);
        h(detail::get<S>(std::move(args))...);
    }

    template<
        class ArgsTuple,
        class ValsTuple,
        std::size_t... S>
    static
    void
    invoke(
        Handler& h,
        ArgsTuple& args,
        ValsTuple&& vals,
        mp11::index_sequence<S...>)
    {
        boost::ignore_unused(args);
        boost::ignore_unused(vals);
        h(extract(detail::get<S>(std::move(args)),
            std::forward<ValsTuple>(vals))...);
    }

public:
    using result_type = void;

    bind_wrapper(bind_wrapper&&) = default;
    bind_wrapper(bind_wrapper const&) = default;

    template<
        class DeducedHandler,
        class... Args_>
    explicit
    bind_wrapper(
        DeducedHandler&& handler,
        Args_&&... args)
        : h_(std::forward<DeducedHandler>(handler))
        , args_(std::forward<Args_>(args)...)
    {
    }

    template<class... Values>
    void
    operator()(Values&&... values)
    {
        invoke(h_, args_,
            tuple<Values&&...>(
                std::forward<Values>(values)...),
            mp11::index_sequence_for<Args...>());
    }

    // VFALCO I don't think this should be needed,
    //        please let me know if something breaks.
    /*
    template<class... Values>
    void
    operator()(Values&&... values) const
    {
        invoke(h_, args_,
            tuple<Values&&...>(
                std::forward<Values>(values)...),
            mp11::index_sequence_for<Args...>());
    }
    */

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
                std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

template<class Handler, class... Args>
class bind_back_wrapper;

template<class Handler, class... Args>
class bind_front_wrapper;

//------------------------------------------------------------------------------
//
// bind_front
//
//------------------------------------------------------------------------------

// 0-arg specialization
template<class Handler>
class bind_front_wrapper<Handler>
{
    Handler h_;

    template<class T, class Executor>
    friend struct net::associated_executor;

public:
    using result_type = void;

    bind_front_wrapper(bind_front_wrapper&&) = default;
    bind_front_wrapper(bind_front_wrapper const&) = default;

    template<class Handler_>
    explicit
    bind_front_wrapper(Handler_&& handler)
        : h_(std::forward<Handler_>(handler))
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_(std::forward<Ts>(ts)...);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_front_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_front_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// 1-arg specialization
template<class Handler, class Arg>
class bind_front_wrapper<Handler, Arg>
{
    Handler h_;
    Arg arg_;

    template<class T, class Executor>
    friend struct net::associated_executor;

public:
    using result_type = void;

    bind_front_wrapper(bind_front_wrapper&&) = default;
    bind_front_wrapper(bind_front_wrapper const&) = default;

    template<
        class Handler_,
        class Arg_>
    bind_front_wrapper(
        Handler_&& handler,
        Arg_&& arg)
        : h_(std::forward<Handler_>(handler))
        , arg_(std::forward<Arg_>(arg))
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_( std::move(arg_),
            std::forward<Ts>(ts)...);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_front_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_front_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// 2-arg specialization
template<class Handler, class Arg1, class Arg2>
class bind_front_wrapper<Handler, Arg1, Arg2>
{
    Handler h_;
    Arg1 arg1_;
    Arg2 arg2_;

    template<class T, class Executor>
    friend struct net::associated_executor;

public:
    using result_type = void;

    bind_front_wrapper(bind_front_wrapper&&) = default;
    bind_front_wrapper(bind_front_wrapper const&) = default;

    template<
        class Handler_,
        class Arg1_,
        class Arg2_>
    bind_front_wrapper(
        Handler_&& handler,
        Arg1_&& arg1,
        Arg2_&& arg2)
        : h_(std::forward<Handler_>(handler))
        , arg1_(std::forward<Arg1_>(arg1))
        , arg2_(std::forward<Arg2_>(arg2))
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_( std::move(arg1_),
            std::move(arg2_),
            std::forward<Ts>(ts)...);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_front_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_front_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// 3+ arg specialization
template<
    class Handler,
    class Arg1, class Arg2, class Arg3,
    class... Args>
class bind_front_wrapper<
    Handler, Arg1, Arg2, Arg3, Args...>
{
    Handler h_;
    detail::tuple<
        Arg1, Arg2, Arg3, Args...> args_;

    template<class T, class Executor>
    friend struct net::associated_executor;

    template<std::size_t... I, class... Ts>
    void
    invoke(
        mp11::index_sequence<I...>,
        Ts&&... ts)
    {
        h_( detail::get<I>(std::move(args_))...,
            std::forward<Ts>(ts)...);
    }

public:
    using result_type = void;

    bind_front_wrapper(bind_front_wrapper&&) = default;
    bind_front_wrapper(bind_front_wrapper const&) = default;

    template<
        class Handler_,
        class Arg1_, class Arg2_, class Arg3_,
        class... Args_>
    bind_front_wrapper(
        Handler_&& handler,
        Arg1_&& arg1,
        Arg2_&& arg2,
        Arg3_&& arg3,
        Args_&&... args)
        : h_(std::forward<Handler_>(handler))
        , args_(
            std::forward<Arg1_>(arg1),
            std::forward<Arg2_>(arg2),
            std::forward<Arg3_>(arg3),
            std::forward<Args_>(args)...)
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        invoke(
            mp11::index_sequence_for<
                Arg1, Arg2, Arg3, Args...>{},
            std::forward<Ts>(ts)...);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_front_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_front_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// specialization for the most common case,
// to reduce instantiation time and memory.
template<class Handler>
class bind_front_wrapper<
    Handler, error_code, std::size_t>
{
    template<class T, class Executor>
    friend struct net::associated_executor;

    Handler h_;
    error_code ec_;
    std::size_t n_;

public:
    using result_type = void;

    bind_front_wrapper(bind_front_wrapper&&) = default;
    bind_front_wrapper(bind_front_wrapper const&) = default;

    template<class DeducedHandler>
    bind_front_wrapper(DeducedHandler&& handler,
        error_code ec, std::size_t n)
        : h_(std::forward<DeducedHandler>(handler))
        , ec_(ec)
        , n_(n)
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_(ec_, n_, std::forward<Ts>(ts)...);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_front_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_front_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_front_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------
//
// bind_back
//
//------------------------------------------------------------------------------

// 0-arg specialization
template<class Handler>
class bind_back_wrapper<Handler>
{
    Handler h_;

    template<class T, class Executor>
    friend struct net::associated_executor;

public:
    using result_type = void;

    bind_back_wrapper(bind_back_wrapper&&) = default;
    bind_back_wrapper(bind_back_wrapper const&) = default;

    template<class Handler_>
    explicit
    bind_back_wrapper(Handler_&& handler)
        : h_(std::forward<Handler_>(handler))
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_(std::forward<Ts>(ts)...);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_back_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_back_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// 1-arg specialization
template<class Handler, class Arg>
class bind_back_wrapper<Handler, Arg>
{
    Handler h_;
    Arg arg_;

    template<class T, class Executor>
    friend struct net::associated_executor;

public:
    using result_type = void;

    bind_back_wrapper(bind_back_wrapper&&) = default;
    bind_back_wrapper(bind_back_wrapper const&) = default;

    template<
        class Handler_,
        class Arg_>
    bind_back_wrapper(
        Handler_&& handler,
        Arg_&& arg)
        : h_(std::forward<Handler_>(handler))
        , arg_(std::forward<Arg_>(arg))
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_( std::forward<Ts>(ts)...,
            std::move(arg_));
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_back_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_back_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// 2-arg specialization
template<class Handler, class Arg1, class Arg2>
class bind_back_wrapper<Handler, Arg1, Arg2>
{
    Handler h_;
    Arg1 arg1_;
    Arg2 arg2_;

    template<class T, class Executor>
    friend struct net::associated_executor;

public:
    using result_type = void;

    bind_back_wrapper(bind_back_wrapper&&) = default;
    bind_back_wrapper(bind_back_wrapper const&) = default;

    template<
        class Handler_,
        class Arg1_,
        class Arg2_>
    bind_back_wrapper(
        Handler_&& handler,
        Arg1_&& arg1,
        Arg2_&& arg2)
        : h_(std::forward<Handler_>(handler))
        , arg1_(std::forward<Arg1_>(arg1))
        , arg2_(std::forward<Arg2_>(arg2))
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_( std::forward<Ts>(ts)...,
            std::move(arg1_),
            std::move(arg2_));
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_back_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_back_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// 3+ arg specialization
template<
    class Handler,
    class Arg1, class Arg2, class Arg3,
    class... Args>
class bind_back_wrapper<
    Handler, Arg1, Arg2, Arg3, Args...>
{
    Handler h_;
    detail::tuple<
        Arg1, Arg2, Arg3, Args...> args_;

    template<class T, class Executor>
    friend struct net::associated_executor;

    template<std::size_t... I, class... Ts>
    void
    invoke(
        mp11::index_sequence<I...>,
        Ts&&... ts)
    {
        h_( std::forward<Ts>(ts)...,
            detail::get<I>(std::move(args_))...);
    }

public:
    using result_type = void;

    bind_back_wrapper(bind_back_wrapper&&) = default;
    bind_back_wrapper(bind_back_wrapper const&) = default;

    template<
        class Handler_,
        class Arg1_, class Arg2_, class Arg3_,
        class... Args_>
    bind_back_wrapper(
        Handler_&& handler,
        Arg1_&& arg1,
        Arg2_&& arg2,
        Arg3_&& arg3,
        Args_&&... args)
        : h_(std::forward<Handler_>(handler))
        , args_(
            std::forward<Arg1_>(arg1),
            std::forward<Arg2_>(arg2),
            std::forward<Arg3_>(arg3),
            std::forward<Args_>(args)...)
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        invoke(
            mp11::index_sequence_for<
                Arg1, Arg2, Arg3, Args...>{},
            std::forward<Ts>(ts)...);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_back_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_back_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

// specialization for the most common case,
// to reduce instantiation time and memory.
template<class Handler>
class bind_back_wrapper<
    Handler, error_code, std::size_t>
{
    template<class T, class Executor>
    friend struct net::associated_executor;

    Handler h_;
    error_code ec_;
    std::size_t n_;

public:
    using result_type = void;

    bind_back_wrapper(bind_back_wrapper&&) = default;
    bind_back_wrapper(bind_back_wrapper const&) = default;

    template<class DeducedHandler>
    bind_back_wrapper(DeducedHandler&& handler,
        error_code ec, std::size_t n)
        : h_(std::forward<DeducedHandler>(handler))
        , ec_(ec)
        , n_(n)
    {
    }

    template<class... Ts>
    void operator()(Ts&&... ts)
    {
        h_(std::forward<Ts>(ts)..., ec_, n_);
    }

    //

    using allocator_type =
        net::associated_allocator_t<Handler>;

    allocator_type
    get_allocator() const noexcept
    {
        return net::get_associated_allocator(h_);
    }

    template<class Function>
    friend
    void asio_handler_invoke(
        Function&& f, bind_back_wrapper* op)
    {
        using net::asio_handler_invoke;
        asio_handler_invoke(f, std::addressof(op->h_));
    }

    friend
    bool asio_handler_is_continuation(
        bind_back_wrapper* op)
    {
        using net::asio_handler_is_continuation;
        return asio_handler_is_continuation(
            std::addressof(op->h_));
    }

    friend
    void* asio_handler_allocate(
        std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_allocate;
        return asio_handler_allocate(
            size, std::addressof(op->h_));
    }

    friend
    void asio_handler_deallocate(
        void* p, std::size_t size, bind_back_wrapper* op)
    {
        using net::asio_handler_deallocate;
        asio_handler_deallocate(
            p, size, std::addressof(op->h_));
    }
};

//------------------------------------------------------------------------------

} // detail
} // beast
} // boost

//------------------------------------------------------------------------------

namespace boost {
namespace asio {

template<class Handler, class... Args, class Executor>
struct associated_executor<
    beast::detail::bind_wrapper<Handler, Args...>, Executor>
{
    using type = typename
        associated_executor<Handler, Executor>::type;

    static
    type
    get(beast::detail::bind_wrapper<Handler, Args...> const& op,
        Executor const& ex = Executor()) noexcept
    {
        return associated_executor<
            Handler, Executor>::get(op.h_, ex);
    }
};

template<class Handler, class... Args, class Executor>
struct associated_executor<
    beast::detail::bind_front_wrapper<Handler, Args...>, Executor>
{
    using type = typename
        associated_executor<Handler, Executor>::type;

    static
    type
    get(beast::detail::bind_front_wrapper<Handler, Args...> const& op,
        Executor const& ex = Executor()) noexcept
    {
        return associated_executor<
            Handler, Executor>::get(op.h_, ex);
    }
};

template<class Handler, class... Args, class Executor>
struct associated_executor<
    beast::detail::bind_back_wrapper<Handler, Args...>, Executor>
{
    using type = typename
        associated_executor<Handler, Executor>::type;

    static
    type
    get(beast::detail::bind_back_wrapper<Handler, Args...> const& op,
        Executor const& ex = Executor()) noexcept
    {
        return associated_executor<
            Handler, Executor>::get(op.h_, ex);
    }
};

} // asio
} // boost

//------------------------------------------------------------------------------

namespace std {

// VFALCO Using std::bind on a completion handler will
// cause undefined behavior later, because the executor
// associated with the handler is not propagated to the
// wrapper returned by std::bind; these overloads are
// deleted to prevent mistakes. If this creates a problem
// please contact me.

template<class Handler, class... Args>
void
bind(boost::beast::detail::bind_wrapper<
    Handler, Args...>, ...) = delete;

template<class Handler, class... Args>
void
bind(boost::beast::detail::bind_front_wrapper<
    Handler, Args...>, ...) = delete;

template<class Handler, class... Args>
void
bind(boost::beast::detail::bind_back_wrapper<
    Handler, Args...>, ...) = delete;

} // std

//------------------------------------------------------------------------------

#endif

max_stars_repo_name: johron/beast

max_issues_repo_name: johron/beast

max_forks_repo_name: johron/beast