text:
// Copyright 2016 Peter Dimov.
//
// Distributed under the Boost Software License, Version 1.0.
//
// See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt

#include <boost/mp11/map.hpp>
#include <boost/mp11/list.hpp>
#include <boost/core/lightweight_test_trait.hpp>
#include <type_traits>
#include <tuple>
#include <utility>

int main()
{
    using boost::mp11::mp_map_insert;
    using boost::mp11::mp_list;
    using boost::mp11::mp_push_back;

    BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<mp_list<>, mp_list<void>>, mp_list<mp_list<void>>>));
    BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<std::tuple<>, std::tuple<int>>, std::tuple<std::tuple<int>>>));
    BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<std::tuple<>, std::pair<int, float>>, std::tuple<std::pair<int, float>>>));

    {
        using M = mp_list<std::pair<int, int const>, std::pair<long, long const>>;

        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<int>>, M>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
    }

    {
        using M = std::tuple<std::pair<int, int const>, std::pair<long, long const>>;

        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<int>>, M>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
    }

    {
        using M = mp_list<mp_list<int>, mp_list<long, long>, mp_list<long long, long long, long long>>;

        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::tuple<int>>, M>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<long long, float, double>>, M>));
    }

    {
        using M = std::tuple<mp_list<int>, std::pair<long, long>, std::tuple<long long, long long, long long>>;

        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<char>>, mp_push_back<M, mp_list<char>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<char, char const>>, mp_push_back<M, std::pair<char, char const>>>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::tuple<int>>, M>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, std::pair<long, float>>, M>));
        BOOST_TEST_TRAIT_TRUE((std::is_same<mp_map_insert<M, mp_list<long long, float, double>>, M>));
    }

    return boost::report_errors();
}

ext: cpp


text:
#include <node/app/plugin.hpp>

#include <boost/multi_index/composite_key.hpp>

//
// Plugins should #define their SPACE_ID's so plugins with
// conflicting SPACE_ID assignments can be compiled into the
// same binary (by simply re-assigning some of the conflicting #defined
// SPACE_ID's in a build script).
//
// Assignment of SPACE_ID's cannot be done at run-time because
// various template automagic depends on them being known at compile
// time.
//
#ifndef ACCOUNT_STATISTICS_SPACE_ID
#define ACCOUNT_STATISTICS_SPACE_ID 10
#endif

#ifndef ACCOUNT_STATISTICS_PLUGIN_NAME
#define ACCOUNT_STATISTICS_PLUGIN_NAME "account_stats"
#endif

namespace node { namespace account_statistics {

using namespace chain;
using app::application;

enum account_statistics_plugin_object_types
{
   account_stats_bucket_object_type    = ( ACCOUNT_STATISTICS_SPACE_ID << 8 ),
   account_activity_bucket_object_type = ( ACCOUNT_STATISTICS_SPACE_ID << 8 ) + 1
};

struct account_stats_bucket_object : public object< account_stats_bucket_object_type, account_stats_bucket_object >
{
   template< typename Constructor, typename Allocator >
   account_stats_bucket_object( Constructor&& c, allocator< Allocator > a )
   {
      c( *this );
   }

   account_stats_bucket_object() {}

   id_type              id;

   fc::time_point_sec   open;                                     ///< Open time of the bucket
   uint32_t             seconds = 0;                              ///< Seconds accounted for in the bucket
   account_name_type    name;                                     ///< Account name
   uint32_t             transactions = 0;                         ///< Transactions this account signed
   uint32_t             market_bandwidth = 0;                     ///< Charged bandwidth for market transactions
   uint32_t             non_market_bandwidth = 0;                 ///< Charged bandwidth for non-market transactions
   uint32_t             total_ops = 0;                            ///< Ops this account was an authority on
   uint32_t             market_ops = 0;                           ///< Market operations
   uint32_t             forum_ops = 0;                            ///< Forum operations
   uint32_t             root_comments = 0;                        ///< Top level root comments
   uint32_t             root_comment_edits = 0;                   ///< Edits to root comments
   uint32_t             root_comments_deleted = 0;                ///< Root comments deleted
   uint32_t             replies = 0;                              ///< Replies to comments
   uint32_t             reply_edits = 0;                          ///< Edits to replies
   uint32_t             replies_deleted = 0;                      ///< Replies deleted
   uint32_t             new_root_votes = 0;                       ///< New votes on root comments
   uint32_t             changed_root_votes = 0;                   ///< Changed votes for root comments
   uint32_t             new_reply_votes = 0;                      ///< New votes on replies
   uint32_t             changed_reply_votes = 0;                  ///< Changed votes for replies
   uint32_t             authorReward_payouts = 0;                ///< Number of author reward payouts
   share_type           authorRewards_TSD = 0;                   ///< TSD paid for author rewards
   share_type           authorRewards_SCORE = 0;                 ///< SCORE paid for author rewards
   share_type           authorRewards_totalTME_value = 0;     ///< TME Value of author rewards
   share_type           authorRewards_payout_TSD_value = 0;      ///< TSD Value of author rewards at time of payout
   uint32_t             curationReward_payouts = 0;              ///< Number of curation reward payouts.
   share_type           curationRewards_SCORE = 0;               ///< SCORE paid for curation rewards
   share_type           curationRewards_TME_value = 0;         ///< TME Value of curation rewards
   share_type           curationRewards_payout_TSD_value = 0;    ///< TSD Value of curation rewards at time of payout
   uint32_t             liquidity_reward_payouts = 0;             ///< Number of liquidity reward payouts
   share_type           liquidity_rewards = 0;                    ///< Amount of TME paid as liquidity rewards
   uint32_t             transfers_to = 0;                         ///< Account to account transfers to this account
   uint32_t             transfers_from = 0;                       ///< Account to account transfers from this account
   share_type           TME_sent = 0;                           ///< TME sent from this account
   share_type           TME_received = 0;                       ///< TME received by this account
   share_type           TSD_sent = 0;                             ///< TSD sent from this account
   share_type           TSD_received = 0;                         ///< TSD received by this account
   uint32_t             TSD_interest_payments = 0;                ///< Number of times interest was paid to TSD
   share_type           TSD_paid_as_interest = 0;                 ///< Amount of TSD paid as interest
   uint32_t             transfers_to_TME_fund_for_SCORE = 0;                 ///< Transfers to SCORE TME fund by this account. Note: Transfer to SCORE TME fund from A to B counts as a transfer from A to B followed by a SCORE TME fund deposit by B.
   share_type           TME_value_of_SCORE = 0;                         ///< SCORE value in TME of the account
   share_type           new_SCORE = 0;                            ///< New SCORE by SCORE TME fund transfers
   uint32_t             new_SCORE_TME_fund_withdrawal_requests = 0;      ///< New SCORE TME fund withdrawal requests
   uint32_t             modified_SCORE_TME_fund_withdrawal_requests = 0; ///< Changes to SCORE TME fund withdraw requests
   uint32_t             TME_fund_for_SCORE_withdrawals_processed = 0;        ///< SCORE TME fund withdrawals processed for this account
   uint32_t             finished_TME_fund_for_SCORE_withdrawals = 0;         ///< Processed SCORE TME fund withdrawals that are now finished
   share_type           SCORE_withdrawn = 0;                      ///< SCORE withdrawn from the account
   share_type           TME_received_from_withdrawls = 0;       ///< TME received from this account's SCORE TME fund withdrawals
   share_type           TME_received_from_routes = 0;           ///< TME received from another account's SCORE TME fund withdrawals
   share_type           SCORE_received_from_routes = 0;           ///< SCORE received from another account's SCORE TME fund withdrawals
   uint32_t             TSD_conversion_requests_created = 0;      ///< TSD conversion requests created
   share_type           TSD_to_be_converted = 0;                  ///< Amount of TSD to be converted
   uint32_t             TSD_conversion_requests_filled = 0;       ///< TSD conversion requests filled
   share_type           TME_converted = 0;                      ///< Amount of TME that was converted
   uint32_t             limit_orders_created = 0;                 ///< Limit orders created by this account
   uint32_t             limit_orders_filled = 0;                  ///< Limit orders filled by this account
   uint32_t             limit_orders_cancelled = 0;               ///< Limit orders cancelled by this account
   share_type           limit_order_TME_paid = 0;               ///< TME paid by limit orders
   share_type           limit_order_TME_received = 0;           ///< TME received from limit orders
   share_type           limit_order_TSD_paid = 0;                 ///< TSD paid by limit orders
   share_type           limit_order_TSD_received = 0;             ///< TSD received by limit orders
   uint32_t             total_pow = 0;                            ///< POW completed
   uint128_t            estimated_hashpower = 0;                  ///< Estimated hashpower
};

typedef account_stats_bucket_object::id_type account_stats_bucket_id_type;

struct account_activity_bucket_object : public object< account_activity_bucket_object_type, account_activity_bucket_object >
{
   template< typename Constructor, typename Allocator >
   account_activity_bucket_object( Constructor&& c, allocator< Allocator > a )
   {
      c( *this );
   }

   account_activity_bucket_object() {}

   id_type              id;

   fc::time_point_sec   open;                                  ///< Open time for the bucket
   uint32_t             seconds = 0;                           ///< Seconds accounted for in the bucket
   uint32_t             active_market_accounts = 0;            ///< Active market accounts in the bucket
   uint32_t             active_forum_accounts = 0;             ///< Active forum accounts in the bucket
   uint32_t             active_market_and_forum_accounts = 0;  ///< Active accounts in both the market and the forum
};

typedef account_activity_bucket_object::id_type account_activity_bucket_id_type;

namespace detail
{
   class account_statistics_plugin_impl;
}

class account_statistics_plugin : public node::app::plugin
{
   public:
      account_statistics_plugin( application* app );
      virtual ~account_statistics_plugin();

      virtual std::string plugin_name()const override { return ACCOUNT_STATISTICS_PLUGIN_NAME; }
      virtual void plugin_set_program_options(
         boost::program_options::options_description& cli,
         boost::program_options::options_description& cfg ) override;
      virtual void plugin_initialize( const boost::program_options::variables_map& options ) override;
      virtual void plugin_startup() override;

      const flat_set< uint32_t >& get_tracked_buckets() const;
      uint32_t get_max_history_per_bucket() const;
      const flat_set< std::string >& get_tracked_accounts() const;

   private:
      friend class detail::account_statistics_plugin_impl;
      std::unique_ptr< detail::account_statistics_plugin_impl > _my;
};

} } // node::account_statistics

FC_REFLECT( node::account_statistics::account_stats_bucket_object,
   (id)
   (open)
   (seconds)
   (name)
   (transactions)
   (market_bandwidth)
   (non_market_bandwidth)
   (total_ops)
   (market_ops)
   (forum_ops)
   (root_comments)
   (root_comment_edits)
   (root_comments_deleted)
   (replies)
   (reply_edits)
   (replies_deleted)
   (new_root_votes)
   (changed_root_votes)
   (new_reply_votes)
   (changed_reply_votes)
   (authorReward_payouts)
   (authorRewards_TSD)
   (authorRewards_SCORE)
   (authorRewards_totalTME_value)
   (authorRewards_payout_TSD_value)
   (curationReward_payouts)
   (curationRewards_SCORE)
   (curationRewards_TME_value)
   (curationRewards_payout_TSD_value)
   (liquidity_reward_payouts)
   (liquidity_rewards)
   (transfers_to)
   (transfers_from)
   (TME_sent)
   (TME_received)
   (TSD_sent)
   (TSD_received)
   (TSD_interest_payments)
   (TSD_paid_as_interest)
   (transfers_to_TME_fund_for_SCORE)
   (TME_value_of_SCORE)
   (new_SCORE)
   (new_SCORE_TME_fund_withdrawal_requests)
   (modified_SCORE_TME_fund_withdrawal_requests)
   (TME_fund_for_SCORE_withdrawals_processed)
   (finished_TME_fund_for_SCORE_withdrawals)
   (SCORE_withdrawn)
   (TME_received_from_withdrawls)
   (TME_received_from_routes)
   (SCORE_received_from_routes)
   (TSD_conversion_requests_created)
   (TSD_to_be_converted)
   (TSD_conversion_requests_filled)
   (TME_converted)
   (limit_orders_created)
   (limit_orders_filled)
   (limit_orders_cancelled)
   (limit_order_TME_paid)
   (limit_order_TME_received)
   (limit_order_TSD_paid)
   (limit_order_TSD_received)
   (total_pow)
   (estimated_hashpower)
)
//SET_INDEX_TYPE( node::account_statistics::account_stats_bucket_object,)

FC_REFLECT(
   node::account_statistics::account_activity_bucket_object,
   (id)
   (open)
   (seconds)
   (active_market_accounts)
   (active_forum_accounts)
   (active_market_and_forum_accounts)
)

ext: hpp

max_stars_repo_name: weyoume/wenode

max_issues_repo_name: weyoume/wenode

max_forks_repo_name: weyoume/wenode


text:
/**
 * Created by sixdi on 2/5/2022.
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <memory>
#include <errno.h>
#include "sts_common.h"
#include <iostream>
#include <cstring>

#include <boost/format.hpp>

test_struct_t test_struct;
result_struct_t res_struct;
char data_buffer[BUFFER_SIZE];

void setup_tcp_server_communication(){
    /**
     * Step 1.  initialization
     */
    /*
     * socket handle and other variables
     * Master socket file descriptor, used to accept new client connection only, no data exchange
     */
    int master_sock_tcp_fd = 0,
        sent_recv_bytes = 0;
    socklen_t   addr_len = 0;
    int    opt = 1;
    /*
     * Client specific communication socket file descriptor,
     * used for only data exchange/communication between client and server
     */
    int comm_sock_fd = 0;

    /*
     * set of file descriptor on which select() polls
     * select() unblock whenever data arrives at any fd present in this set.
     */
    fd_set read_fds;

    /*
     * variables to hold server information
     * structures to store the server and client info;
     */
    struct sockaddr_in server_addr, client_addr;

    /**
     * Step 2. TCP master socket creation
     */
    if (-1 == (master_sock_tcp_fd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP))){
        perror("socket creation failed\n");
        exit(EXIT_FAILURE);
    }

    /**
     * Step 3. Specify Server info
     */
    server_addr.sin_family = AF_INET; // this socket will process only IPv4 network packets
    server_addr.sin_port = SERVER_PORT; // Server will process any data arriving at port# SERVER_PORT

    /*
    * server's IP address,
    * INADDR_ANY is used when we don't want to bind a socket to any specific IP.
    * Basically, while implementing communication, we need to bind our socket to an IP.
    * When we don't know the IP of our machine, we can use the special IP - INADDR_ANY,
    * it allows our server to receive PKT that have been targeted by any of the interfaces.
    */
    server_addr.sin_addr.s_addr = INADDR_ANY;
    addr_len = sizeof (struct sockaddr);

    /*
     * Bind the server,
     * Binding means, we are telling kernel(OS) that any data
     * it receives with DST IP = server IP, and TCP port # = SERVER_PORT,
     * send that data to this process.
     *
     * bind() is a mechanism to tell OS what kind of data server process is interested in to receive.
     * server machine can run multiple server processes to process different data and service different clients.
     *
     * bind() is used only on server side.
     */
    if ( -1 == bind(master_sock_tcp_fd, (struct sockaddr*)&server_addr, sizeof(struct sockaddr))){
        perror("socket bind failed\n");
        exit(EXIT_FAILURE);
    }

    /**
     * Step 4. Tell the OS to maintain the queue of max length to Queue incoming client connections
     */
    if (listen(master_sock_tcp_fd, MAX_INCOMING_QUEUE) < 0){
        perror("listen failed");
        exit(EXIT_FAILURE);
    }

    /**
     * Server infinite loop for servicing the client
     */
    while(true){
        /**
         * Step 5. initialize and fill read_fds
         */
        FD_ZERO(&read_fds); // initialize the file descriptor set
        FD_SET(master_sock_tcp_fd, &read_fds); // add teh socket to this set on which the server is running

        std::cout << "blocked on select system call" << std::endl;

        /**
         * Step 6. Wait for Client connection
         */
        /*
         * state machine state 1
         * call the select() system call, server process blocks here.
         * OS keeps this process blocked until the data arrives on any fo the file descriptors
         * in the read_fds;
         */
        select(master_sock_tcp_fd+1, &read_fds, nullptr, nullptr, nullptr);

        /*
         * some data on some fd present in set has arrived,
         * check on which file descriptor the data arrives, and process accordingly
         */
        if (FD_ISSET(master_sock_tcp_fd, &read_fds)){
            /*
             * data arrives on Master socket only when new client connects with the server
             * that is connect() call is invoked on client side
             */
            std::cout << "New connection recieved recvd, accept the connection. "
                         "Client and Server completes TCP-3 way handshake at this point" << std::endl;

            /**
             * Step 7.
             *  accept() returns a new temporary file descriptor(fd)
             *  server uses this `comm_sock_fd` for the rest of the life of connection with this client
             *  to send and receive msg.
             *
             *  master socket is used only for accepting new client's connection and not for data exchange with the client
             */
             /*
              * state machine state 2
              */
             comm_sock_fd = accept(master_sock_tcp_fd, (struct sockaddr*)&client_addr, &addr_len);
             if(comm_sock_fd < 0){
                 printf("accept error: errno = %d\n", errno);
                 exit(EXIT_FAILURE);
             }

             std::cout << boost::format("Connection accepted from client %1%:%2%")
                            % inet_ntoa(client_addr.sin_addr)
                            % ntohs(client_addr.sin_port)
                        << std::endl;

             while(true){
                 std::cout << "Server ready to serve client msgs" << std::endl;
                 /*
                  * Drain to store client info(ip and port) when data arrives from client,
                  * sometimes server would want to find the identity of the client sending msg
                  */
                 memset(data_buffer, 0, sizeof(data_buffer));

                 /**
                  * Step 8.
                  * Server receiving the data from client.
                  * Client IP and PORT# will be stored in client_addr by the kernel.
                  * server will use this client_addr info to replay back to client
                  */

                 /*
                  * this is also a blocking system call,
                  * meaning, server process halts here until data arrives on this comm_socket_fd
                  * from client whose connection request has been accepted via accept()
                  */
                 /*
                  * state machine state 3
                  */
                 sent_recv_bytes = recvfrom(comm_sock_fd, (char*)data_buffer, sizeof(data_buffer), 0,
                                            (struct sockaddr*)&client_addr, &addr_len);

                 /*
                  * state machine state 4
                  */
                 std::cout << boost::format("Server received %1% bytes from client %2%:%3% \n")
                                % sent_recv_bytes
                                % inet_ntoa(client_addr.sin_addr)
                                % ntohs(client_addr.sin_port);

                 if (sent_recv_bytes == 0){
                     /*
                      * if server receives empty msg from client, server may close the connection and wait
                      * for fresh new connection from client - same or different
                      */
                     close(comm_sock_fd);
                     break; // goto step 5
                 }

                 test_struct_t *client_data = (test_struct_t*) data_buffer;
                 /*
                  * if the client sends a special msg to server,
                  * then server close the client connection forever
                  */
                 /**
                  * step 9.
                  */
                 if(client_data->a == 0 && client_data->b == 0){
                     close(comm_sock_fd);
                     std::cout << boost::format("Server close connection with client: %1%:%2%\n")
                                % inet_ntoa(client_addr.sin_addr)
                                % ntohs(client_addr.sin_port);
                     // Goto state 1
                     break; // get out of inner while loop, server is done with this client,
                            // time to check for new connection request by executing select()
                 }

                 result_struct_t result;
                 result.c = client_data->a + client_data->b;

                 /*
                  * Server replying to client now
                  */
                 sent_recv_bytes = sendto(comm_sock_fd, (char*) &result, sizeof(result_struct_t), 0,
                                          (struct sockaddr*)&client_addr, sizeof(struct sockaddr));

                 std::cout << boost::format("Server sent %1% bytes in reply to client \n") % sent_recv_bytes ;
                 /*
                  * Goto state machine state 3
                  */
             }
        }
    } // step 10, wait for new client request again
}

int main(int argc, char** argv){
    setup_tcp_server_communication();
    exit(EXIT_SUCCESS);
}


text:
//  (C) Copyright Steve Cleary, Beman Dawes, Howard Hinnant & John Maddock 2000.
//  Use, modification and distribution are 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).
//
//  See http://www.boost.org/libs/type_traits for most recent version including documentation.

#ifndef BOOST_TT_HAS_TRIVIAL_CONSTRUCTOR_HPP_INCLUDED
#define BOOST_TT_HAS_TRIVIAL_CONSTRUCTOR_HPP_INCLUDED

#include <boost/type_traits/intrinsics.hpp>
#include <boost/type_traits/is_pod.hpp>
#include <boost/type_traits/is_default_constructible.hpp>

#ifdef BOOST_HAS_TRIVIAL_CONSTRUCTOR
#ifdef BOOST_HAS_SGI_TYPE_TRAITS
#include <boost/type_traits/is_same.hpp>
#elif defined(__GNUC__) || defined(__SUNPRO_CC)
#include <boost/type_traits/is_volatile.hpp>
#ifdef BOOST_INTEL
#include <boost/type_traits/is_pod.hpp>
#endif
#endif
#endif

#if (defined(__GNUC__) && (__GNUC__ * 100 + __GNUC_MINOR__ >= 409)) || defined(BOOST_CLANG) || (defined(__SUNPRO_CC) && defined(BOOST_HAS_TRIVIAL_CONSTRUCTOR))
#include <boost/type_traits/is_default_constructible.hpp>
#define BOOST_TT_TRIVIAL_CONSTRUCT_FIX && is_default_constructible<T>::value
#else
//
// Mot all compilers, particularly older GCC versions can handle the fix above.
#define BOOST_TT_TRIVIAL_CONSTRUCT_FIX
#endif

namespace boost {

template <typename T> struct has_trivial_constructor
#ifdef BOOST_HAS_TRIVIAL_CONSTRUCTOR
   : public integral_constant <bool, ((::boost::is_pod<T>::value || BOOST_HAS_TRIVIAL_CONSTRUCTOR(T)) BOOST_TT_TRIVIAL_CONSTRUCT_FIX)>{};
#else
   : public integral_constant <bool, ::boost::is_pod<T>::value>{};
#endif

template <> struct has_trivial_constructor<void> : public boost::false_type{};
template <> struct has_trivial_constructor<void const> : public boost::false_type{};
template <> struct has_trivial_constructor<void const volatile> : public boost::false_type{};
template <> struct has_trivial_constructor<void volatile> : public boost::false_type{};

template <class T> struct has_trivial_default_constructor : public has_trivial_constructor<T> {};

#undef BOOST_TT_TRIVIAL_CONSTRUCT_FIX

} // namespace boost

#endif // BOOST_TT_HAS_TRIVIAL_CONSTRUCTOR_HPP_INCLUDED

max_stars_repo_name: rudylee/expo

max_issues_repo_name: rudylee/expo

max_forks_repo_name: rudylee/expo


text:
#ifndef _UTILS_H
#define _UTILS_H

/* C++ includes */

#include <iostream>
#include <chrono>
#include <functional>
#include <iomanip>
#include <random>
#include <algorithm>
#include <string>
#include <fstream>

/* C includes */

#include <stdlib.h>
#include <stdio.h>
#include <time.h>
#include <math.h>
#include <assert.h>
#include <sys/time.h>

#include "json/json.h"

#include <boost/program_options.hpp>
namespace po = boost::program_options;

double stime();

void show_params(uint, uint, uint, uint, uint, std::string);

std::string toString(uint);

void save_json(std::vector< std::tuple<uint, float, float, float, float > > &, std::ofstream& );
void save_diversity(std::vector< std::tuple<uint, float, float, float, float > > &, std::ofstream& );

#endif


text:
#ifndef PARMCB_DETAIL_SIGNED_DIJKSTRA_HPP_
#define PARMCB_DETAIL_SIGNED_DIJKSTRA_HPP_

//    Copyright (C) Dimitrios Michail 2019 - 2021.
// Distributed under the Boost Software License, Version 1.0.
//    (See accompanying file LICENSE_1_0.txt or copy at
//          https://www.boost.org/LICENSE_1_0.txt)

#include <iostream>

#include <boost/scoped_array.hpp>
#include <boost/throw_exception.hpp>
#include <boost/functional/hash.hpp>
#include <boost/property_map/property_map.hpp>
#include <boost/property_map/function_property_map.hpp>
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/graph/adjacency_list.hpp>
#include <boost/graph/detail/d_ary_heap.hpp>

#include <parmcb/detail/util.hpp>

namespace std {

    std::ostream& operator <<(std::ostream &out, const std::pair<unsigned long int, bool> &v) {
        out << v.first << (v.second ? "+" : "-");
        return out;
    }

}

namespace parmcb {

    namespace detail {

        template<class Graph, class WeightMap>
        struct SignedDistanceFunctor {
            typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
            typedef typename boost::property_traits<WeightMap>::value_type DistanceType;
            typedef typename boost::property_map<Graph, boost::vertex_index_t>::type VertexIndexMapType;
            typedef std::pair<Vertex, bool> SignedVertex;

            std::size_t n;
            std::vector<DistanceType> &dist;
            const VertexIndexMapType &index_map;

            SignedDistanceFunctor(std::size_t n, std::vector<DistanceType> &dist, const VertexIndexMapType &index_map) :
                    n(n), dist(dist), index_map(index_map) {
            }

            DistanceType& operator()(const SignedVertex &v) const {
                return dist.at(index_map[v.first] + (v.second ? 0 : n));
            }
        };

        template<class Graph>
        struct SignedPredecessorFunctor {
            typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
            typedef typename boost::property_map<Graph, boost::vertex_index_t>::type VertexIndexMapType;
            typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
            typedef std::pair<Vertex, bool> SignedVertex;
            typedef std::tuple<SignedVertex, bool, Edge> Predecessor;

            std::size_t n;
            std::vector<Predecessor> &pred;
            const VertexIndexMapType &index_map;

            SignedPredecessorFunctor(std::size_t n, std::vector<Predecessor> &pred, const VertexIndexMapType &index_map) :
                    n(n), pred(pred), index_map(index_map) {
            }

            Predecessor& operator()(const SignedVertex &v) const {
                return pred.at(index_map[v.first] + (v.second ? 0 : n));
            }
        };

        template<class Graph>
        struct SignedIndexInHeapFunctor {
            typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
            typedef typename boost::property_map<Graph, boost::vertex_index_t>::type VertexIndexMapType;
            typedef std::pair<Vertex, bool> SignedVertex;

            std::size_t n;
            std::vector<std::size_t> &index_in_heap;
            const VertexIndexMapType &index_map;

            SignedIndexInHeapFunctor(std::size_t n, std::vector<std::size_t> &index_in_heap,
                    const VertexIndexMapType &index_map) :
                    n(n), index_in_heap(index_in_heap), index_map(index_map) {
            }

            std::size_t& operator()(const SignedVertex &v) const {
                return index_in_heap.at(index_map[v.first] + (v.second ? 0 : n));
            }
        };

        template<class Graph, class WeightMap>
        struct search_frontier {
            typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
            typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
            typedef typename boost::property_traits<WeightMap>::value_type WeightType;
            typedef typename boost::property_traits<WeightMap>::value_type DistanceType;
            typedef typename boost::property_map<Graph, boost::vertex_index_t>::type VertexIndexMapType;
            typedef std::pair<Vertex, bool> SignedVertex;
            typedef std::tuple<SignedVertex, bool, Edge> Predecessor;
            typedef boost::d_ary_heap_indirect<SignedVertex, 4,
                    boost::function_property_map<parmcb::detail::SignedIndexInHeapFunctor<Graph>, SignedVertex,
                            std::size_t&>,
                    boost::function_property_map<parmcb::detail::SignedDistanceFunctor<Graph, WeightMap>, SignedVertex,
                            DistanceType&>, std::less<DistanceType>> VertexQueue;

            const Graph &g;
            const VertexIndexMapType index_map;
            std::vector<std::size_t> index_in_heap;
            std::vector<DistanceType> dist;
            std::vector<Predecessor> pred;
            boost::function_property_map<parmcb::detail::SignedIndexInHeapFunctor<Graph>, SignedVertex, std::size_t&> index_in_heap_map;
            boost::function_property_map<parmcb::detail::SignedDistanceFunctor<Graph, WeightMap>, SignedVertex,
                    DistanceType&> dist_map;
            boost::function_property_map<parmcb::detail::SignedPredecessorFunctor<Graph>, SignedVertex, Predecessor&> pred_map;
            std::less<DistanceType> compare;
            VertexQueue queue;
            SignedVertex source;

            search_frontier(const Graph &g) :
                    g(g), index_map(boost::get(boost::vertex_index, g)), index_in_heap(2 * boost::num_vertices(g)), dist(
                            2 * boost::num_vertices(g), (std::numeric_limits<DistanceType>::max)()), pred(
                            2 * boost::num_vertices(g), std::make_tuple(std::make_pair(Vertex(), true), false, Edge())), index_in_heap_map(
                            parmcb::detail::SignedIndexInHeapFunctor<Graph>(boost::num_vertices(g), index_in_heap,
                                    index_map)), dist_map(
                            parmcb::detail::SignedDistanceFunctor<Graph, WeightMap>(boost::num_vertices(g), dist,
                                    index_map)), pred_map(
                            parmcb::detail::SignedPredecessorFunctor<Graph>(boost::num_vertices(g), pred, index_map)), compare(), queue(
                            dist_map, index_in_heap_map, compare) {
            }

            SignedVertex poll() {
                SignedVertex u = queue.top();
                queue.pop();
                return u;
            }

            const DistanceType& find_min() {
                SignedVertex u = queue.top();
                return boost::get(dist_map, u);
            }

            bool has_finite_dist(const SignedVertex &u) {
                return u == source || std::get<1>(boost::get(pred_map, u));
            }

            const DistanceType& get_dist(const SignedVertex &u) {
                return boost::get(dist_map, u);
            }

            const Predecessor& get_pred(const SignedVertex &u) {
                return boost::get(pred_map, u);
            }

            void push_source(SignedVertex s) {
                boost::put(dist_map, s, DistanceType());
                queue.push(s);
                source = s;
            }

            SignedVertex get_source() {
                return source;
            }

            void update(SignedVertex w, const DistanceType &c, const SignedVertex &pred, const Edge &pred_e) {
                if (w == source) {
                    return;
                }
                bool visited_w = std::get<1>(boost::get(pred_map, w));

                if (!visited_w) {
                    // first time found
                    boost::put(dist_map, w, c);
                    boost::put(pred_map, w, std::make_tuple(pred, true, pred_e));
                    queue.push(w);
                } else if (compare(c, boost::get(dist_map, w))) {
                    // already reached
                    boost::put(dist_map, w, c);
                    boost::put(pred_map, w, std::make_tuple(pred, true, pred_e));
                    queue.update(w);
                }
            }

        };

    } // detail

    template<class Graph, class WeightMap, class SignedEdges, class HiddenEdges>
    std::tuple<std::set<typename boost::graph_traits<Graph>::edge_descriptor>,
            typename boost::property_traits<WeightMap>::value_type, bool> signed_dijkstra(const Graph &g,
            const WeightMap &weight_map, const SignedEdges &signed_edges, const HiddenEdges &hidden_edges,
            bool use_hidden_edges, const typename boost::graph_traits<Graph>::vertex_descriptor &s, bool s_pos,
            const typename boost::graph_traits<Graph>::vertex_descriptor &t, bool t_pos, bool use_cycle_weight_limit,
            const typename boost::property_traits<WeightMap>::value_type &cycle_weight_limit) {

        typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
        typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
        typedef typename boost::property_traits<WeightMap>::value_type WeightType;
        typedef typename boost::property_traits<WeightMap>::value_type DistanceType;
        typedef std::pair<Vertex, bool> SignedVertex;
        typedef std::tuple<SignedVertex, bool, Edge> Predecessor;

        DistanceType distance_inf = (std::numeric_limits<DistanceType>::max)();
        std::less<DistanceType> compare;
        parmcb::detail::closed_plus<DistanceType> combine = parmcb::detail::closed_plus<DistanceType>();

        parmcb::detail::search_frontier<Graph, WeightMap> frontier(g);
        SignedVertex signed_s = std::make_pair(s, s_pos);
        SignedVertex signed_t = std::make_pair(t, t_pos);
        frontier.push_source(signed_s);

        assert(signed_s != signed_t);

        while (!frontier.queue.empty()) {
            SignedVertex signed_u = frontier.poll();
            DistanceType d_u = frontier.get_dist(signed_u);
            auto u = signed_u.first;

            if (use_cycle_weight_limit && !compare(d_u, cycle_weight_limit)) {
                // reached limit
                return std::make_tuple(std::set<Edge> { }, distance_inf, false);
            }

            if (signed_u == signed_t) { // found target
                std::set<Edge> cycle;
                WeightType cycle_weight = WeightType();
                SignedVertex signed_cur = signed_t;
                while (signed_cur != signed_s) {
                    Predecessor p = frontier.get_pred(signed_cur);
                    Edge e = std::get<2>(p);
                    if (!cycle.insert(e).second) {
                        // duplicate edge, discard cycle
                        return std::make_pair(std::set<Edge> { }, distance_inf);
                    } else {
                        cycle_weight += get(weight_map, e);
                    }
                    signed_cur = std::get<0>(p);
                }
                return std::make_tuple(cycle, cycle_weight, true);
            }

            auto eiRange = boost::out_edges(signed_u.first, g);
            for (auto ei = eiRange.first; ei != eiRange.second; ++ei) {
                auto e = *ei;
                if (use_hidden_edges && hidden_edges.find(e) != hidden_edges.end()) {
                    continue;
                }

                auto w = boost::target(e, g);
                if (w == u) {
                    w = boost::source(e, g);
                }
                if (w == u) {
                    // self-loop
                    continue;
                }
                const WeightType c = combine(d_u, get(weight_map, e));

                if (use_cycle_weight_limit && !compare(c, cycle_weight_limit)) {
                    // never insert if more than current minimum
                    continue;
                }

                bool is_signed = (signed_edges.find(e) != signed_edges.end());
                SignedVertex signed_w = std::make_pair(w, is_signed ? (!signed_u.second) : signed_u.second);

                frontier.update(signed_w, c, signed_u, e);
            }

        }

        return std::make_tuple(std::set<Edge> { }, distance_inf, false);
    }

    template<class Graph, class WeightMap, class SignedEdges, class HiddenEdges>
    std::tuple<std::set<typename boost::graph_traits<Graph>::edge_descriptor>,
            typename boost::property_traits<WeightMap>::value_type, bool> bidirectional_signed_dijkstra(const Graph &g,
            const WeightMap &weight_map, const SignedEdges &signed_edges, const HiddenEdges &hidden_edges,
            bool use_hidden_edges, const typename boost::graph_traits<Graph>::vertex_descriptor &s, bool s_pos,
            const typename boost::graph_traits<Graph>::vertex_descriptor &t, bool t_pos, bool use_cycle_weight_limit,
            const typename boost::property_traits<WeightMap>::value_type &cycle_weight_limit) {

        typedef typename boost::graph_traits<Graph>::vertex_descriptor Vertex;
        typedef typename boost::graph_traits<Graph>::edge_descriptor Edge;
        typedef typename boost::property_traits<WeightMap>::value_type WeightType;
        typedef typename boost::property_traits<WeightMap>::value_type DistanceType;
        typedef std::pair<Vertex, bool> SignedVertex;
        typedef std::tuple<SignedVertex, bool, Edge> Predecessor;

        DistanceType distance_inf = (std::numeric_limits<DistanceType>::max)();
        std::less<DistanceType> compare;
        parmcb::detail::closed_plus<DistanceType> combine = parmcb::detail::closed_plus<DistanceType>();

        SignedVertex signed_s = std::make_pair(s, s_pos);
        parmcb::detail::search_frontier<Graph, WeightMap> f_frontier(g);
        f_frontier.push_source(signed_s);

        SignedVertex signed_t = std::make_pair(t, t_pos);
        parmcb::detail::search_frontier<Graph, WeightMap> b_frontier(g);
        b_frontier.push_source(signed_t);

        assert(signed_s != signed_t);

        std::reference_wrapper<parmcb::detail::search_frontier<Graph, WeightMap>> frontier = std::ref(f_frontier);
        std::reference_wrapper<parmcb::detail::search_frontier<Graph, WeightMap>> other_frontier = std::ref(b_frontier);
        DistanceType best_path = distance_inf;
        bool best_path_set = false;
        SignedVertex best_path_common_vertex;

        while (true) {
            // stopping condition
            if (frontier.get().queue.empty() || other_frontier.get().queue.empty()
                    || (best_path_set
                            && !compare(combine(frontier.get().find_min(), other_frontier.get().find_min()), best_path))) {
                break;
            }

            // frontier scan
            SignedVertex signed_u = frontier.get().poll();
            DistanceType d_u = frontier.get().get_dist(signed_u);
            auto u = signed_u.first;

            if (use_cycle_weight_limit && !compare(d_u, cycle_weight_limit)) {
                // reached limit
                return std::make_tuple(std::set<Edge> { }, distance_inf, false);
            }

            auto eiRange = boost::out_edges(signed_u.first, g);
            for (auto ei = eiRange.first; ei != eiRange.second; ++ei) {
                auto e = *ei;
                if (use_hidden_edges && hidden_edges.find(e) != hidden_edges.end()) {
                    continue;
                }
                auto w = boost::target(e, g);
                if (w == u) {
                    w = boost::source(e, g);
                }
                if (w == u) {
                    // self-loop
                    continue;
                }

                const WeightType c = combine(d_u, get(weight_map, e));
                if (use_cycle_weight_limit && !frontier.get().compare(c, cycle_weight_limit)) {
                    // never insert if more than current minimum
                    continue;
                }

                bool is_signed = (signed_edges.find(e) != signed_edges.end());
                SignedVertex signed_w = std::make_pair(w, is_signed ? (!signed_u.second) : signed_u.second);

                frontier.get().update(signed_w, c, signed_u, e);

                if (other_frontier.get().has_finite_dist(signed_w)) {
                    // check path with w's distance from other frontier
                    DistanceType path_distance = combine(c, other_frontier.get().get_dist(signed_w));
                    if (compare(path_distance, best_path)) {
                        best_path_set = true;
                        best_path = path_distance;
                        best_path_common_vertex = signed_w;
                    }
                }

            }

            // swap frontiers
            std::swap(frontier, other_frontier);
        }

        if (!best_path_set || (use_cycle_weight_limit && !compare(best_path, cycle_weight_limit))) {
            return std::make_tuple(std::set<Edge> { }, distance_inf, false);
        }

        // create path if found
        std::set<Edge> cycle;
        WeightType cycle_weight = WeightType();

        SignedVertex signed_cur = best_path_common_vertex;
        SignedVertex signed_goal = frontier.get().get_source();
        while (signed_cur != signed_goal) {
            Predecessor p = frontier.get().get_pred(signed_cur);
            Edge e = std::get<2>(p);
            if (!cycle.insert(e).second) {
                // duplicate edge, discard cycle
                return std::make_tuple(std::set<Edge> { }, distance_inf, false);
            } else {
                cycle_weight += boost::get(weight_map, e);
            }
            signed_cur = std::get<0>(p);
        }

        signed_cur = best_path_common_vertex;
        signed_goal = other_frontier.get().get_source();
        while (signed_cur != signed_goal) {
            Predecessor p = other_frontier.get().get_pred(signed_cur);
            Edge e = std::get<2>(p);
            if (!cycle.insert(e).second) {
                // duplicate edge, discard cycle
                return std::make_tuple(std::set<Edge> { }, distance_inf, false);
            } else {
                cycle_weight += boost::get(weight_map, e);
            }
            signed_cur = std::get<0>(p);
        }
        return std::make_tuple(cycle, cycle_weight, true);
    }

} // parmcb

#endif

max_stars_repo_name: d-michail/parmcb

max_issues_repo_name: d-michail/parmcb

max_forks_repo_name: d-michail/parmcb


text: #include <boost/math/distributions/non_central_beta.hpp>

max_stars_repo_name: miathedev/BoostForArduino

max_issues_repo_name: miathedev/BoostForArduino

max_forks_repo_name: miathedev/BoostForArduino


text:
/**
 Boost Logging library

 Author: John Torjo, www.torjo.com

 Copyright (C) 2007 John Torjo (see www.torjo.com for email)

 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)

 See http://www.boost.org for updates, documentation, and revision history.
 See http://www.torjo.com/log2/ for more details
*/

/**
@example mul_levels_mul_logers.cpp

@copydoc mul_levels_mul_logers

@page mul_levels_mul_logers mul_levels_mul_logers.cpp Example

This usage:
- You have multiple levels (in this example: debug < info < error)
- You want to format the message before it's written
  (in this example: prefix it by time, by index and append newline to it)
- You have several loggers
- Each logger has several log destinations

Optimizations:
- use a cache string (from optimize namespace), in order to make formatting the message faster

Logs:
- Error messages go into err.txt file
  - formatting - prefix each message by time, index, and append newline
- Info output goes to console, and a file called out.txt
  - formatting - prefix each message by "[app]", time, and append newline
- Debug messages go to the debug output window, and a file called out.txt
  - formatting - prefix each message by "[dbg]", time, and append newline

Here's how the output will look like:

The debug output window:
@code
07:52.30 [dbg] this is so cool 1
07:52.30 [dbg] this is so cool again 2
@endcode

The console:
@code
07:52.30 [app] hello, world
07:52.30 [app] good to be back ;) 4
@endcode

The out.txt file:
@code
07:52.30 [dbg] this is so cool 1
07:52.30 [dbg] this is so cool again 2
07:52.30 [app] hello, world
07:52.30 [app] good to be back ;) 4
@endcode

The err.txt file
@code
07:52.30 [1] first error 3
07:52.30 [2] second error 5
@endcode
*/

#include <boost/logging/format/named_write.hpp>
typedef boost::logging::named_logger<>::type logger_type;

#define LDBG_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_dbg(), g_log_level(), debug ) << "[dbg] "
#define LERR_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_err(), g_log_level(), error )
#define LAPP_ BOOST_LOG_USE_LOG_IF_LEVEL(g_log_app(), g_log_level(), info ) << "[app] "

BOOST_DEFINE_LOG_FILTER(g_log_level, boost::logging::level::holder )
BOOST_DEFINE_LOG(g_log_err, logger_type)
BOOST_DEFINE_LOG(g_log_app, logger_type)
BOOST_DEFINE_LOG(g_log_dbg, logger_type)

using namespace boost::logging;

void mul_levels_mul_logers_example() {
    // reuse the same destination for 2 logs
    destination::file out("out.txt");
    g_log_app()->writer().replace_destination("file", out);
    g_log_dbg()->writer().replace_destination("file", out);
    // formatting (first param) and destinations (second param)
    g_log_err()->writer().write("[%idx%] %time%($hh:$mm.$ss) |\n", "cout file(err.txt)"); // line A
    g_log_app()->writer().write("%time%($hh:$mm.$ss) |\n", "file cout");
    g_log_dbg()->writer().write("%time%($hh:$mm.$ss) |\n", "file cout debug");

    /*
    Note : the "line A" above originally was:
    g_log_err()->writer().write("[%idx%] %time%($hh:$mm.$ss) |\n", "file(err.txt)");

    This caused a very strange assertion failure on Fedora8, when the program exits, while destroying the global variables.
    I've spent some time debugging it but to no avail. I will certainly look more into this.
    */

    g_log_app()->mark_as_initialized();
    g_log_err()->mark_as_initialized();
    g_log_dbg()->mark_as_initialized();

    int i = 1;
    LDBG_ << "this is so cool " << i++;
    LDBG_ << "this is so cool again " << i++;
    LERR_ << "first error " << i++;

    std::string hello = "hello", world = "world";
    LAPP_ << hello << ", " << world;

    g_log_level()->set_enabled(level::error);
    LDBG_ << "this will not be written anywhere";
    LAPP_ << "this won't be written anywhere either";

    g_log_level()->set_enabled(level::info);
    LAPP_ << "good to be back ;) " << i++;
    LERR_ << "second error " << i++;
}

int main() {
    mul_levels_mul_logers_example();
}

// End of file

max_stars_repo_name: gbucknell/fsc-sdk

max_issues_repo_name: gbucknell/fsc-sdk

max_forks_repo_name: gbucknell/fsc-sdk


text:
//
// Copyright 2007-2012 Christian Henning, Andreas Pokorny, Lubomir Bourdev
//
// 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
//
#ifndef BOOST_GIL_IO_READ_IMAGE_HPP
#define BOOST_GIL_IO_READ_IMAGE_HPP

#include <boost/gil/extension/toolbox/dynamic_images.hpp>

#include <boost/gil/detail/mp11.hpp>
#include <boost/gil/io/base.hpp>
#include <boost/gil/io/conversion_policies.hpp>
#include <boost/gil/io/device.hpp>
#include <boost/gil/io/get_reader.hpp>
#include <boost/gil/io/path_spec.hpp>

#include <type_traits>

namespace boost {
namespace gil {

/// \ingroup IO

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param reader    An image reader.
/// \param img       The image in which the data is read into. Must satisfy
/// is_read_supported metafunction. \throw std::ios_base::failure
template <typename Reader, typename Image>
inline void read_image(
    Reader reader, Image &img,
    typename std::enable_if<mp11::mp_and<
        detail::is_reader<Reader>, is_format_tag<typename Reader::format_tag_t>,
        is_read_supported<typename get_pixel_type<typename Image::view_t>::type,
                          typename Reader::format_tag_t>>::value>::type
        * /*dummy*/
    = nullptr) {
  reader.init_image(img, reader._settings);
  reader.apply(view(img));
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file      It's a device. Must satisfy is_input_device metafunction.
/// \param img       The image in which the data is read into. Must satisfy
/// is_read_supported metafunction. \param settings  Specifies read settings
/// depending on the image format. \throw std::ios_base::failure
template <typename Device, typename Image, typename FormatTag>
inline void read_image(
    Device &file, Image &img, image_read_settings<FormatTag> const &settings,
    typename std::enable_if<mp11::mp_and<
        detail::is_read_device<FormatTag, Device>, is_format_tag<FormatTag>,
        is_read_supported<typename get_pixel_type<typename Image::view_t>::type,
                          FormatTag>>::value>::type * /*dummy*/
    = nullptr) {
  using reader_t =
      typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;

  reader_t reader = make_reader(file, settings, detail::read_and_no_convert());
  read_image(reader, img);
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file      It's a device. Must satisfy is_input_device metafunction.
/// \param img       The image in which the data is read into. Must satisfy
/// is_read_supported metafunction. \param tag       Defines the image format.
/// Must satisfy is_format_tag metafunction. \throw std::ios_base::failure
template <typename Device, typename Image, typename FormatTag>
inline void read_image(
    Device &file, Image &img, FormatTag const &tag,
    typename std::enable_if<mp11::mp_and<
        detail::is_read_device<FormatTag, Device>, is_format_tag<FormatTag>,
        is_read_supported<typename get_pixel_type<typename Image::view_t>::type,
                          FormatTag>>::value>::type * /*dummy*/
    = nullptr) {
  using reader_t =
      typename get_reader<Device, FormatTag, detail::read_and_no_convert>::type;

  reader_t reader = make_reader(file, tag, detail::read_and_no_convert());
  read_image(reader, img);
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file_name File name. Must satisfy is_supported_path_spec
/// metafunction. \param img       The image in which the data is read into.
/// Must satisfy is_read_supported metafunction. \param settings  Specifies read
/// settings depending on the image format. \throw std::ios_base::failure
template <typename String, typename Image, typename FormatTag>
inline void read_image(
    String const &file_name, Image &img,
    image_read_settings<FormatTag> const &settings,
    typename std::enable_if<mp11::mp_and<
        detail::is_supported_path_spec<String>, is_format_tag<FormatTag>,
        is_read_supported<typename get_pixel_type<typename Image::view_t>::type,
                          FormatTag>>::value>::type * /*dummy*/
    = nullptr) {
  using reader_t =
      typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;

  reader_t reader =
      make_reader(file_name, settings, detail::read_and_no_convert());
  read_image(reader, img);
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file_name File name. Must satisfy is_supported_path_spec
/// metafunction. \param img       The image in which the data is read into.
/// Must satisfy is_read_supported metafunction. \param tag       Defines the
/// image format. Must satisfy is_format_tag metafunction. \throw
/// std::ios_base::failure
template <typename String, typename Image, typename FormatTag>
inline void read_image(
    String const &file_name, Image &img, FormatTag const &tag,
    typename std::enable_if<mp11::mp_and<
        detail::is_supported_path_spec<String>, is_format_tag<FormatTag>,
        is_read_supported<typename get_pixel_type<typename Image::view_t>::type,
                          FormatTag>>::value>::type * /*dummy*/
    = nullptr) {
  using reader_t =
      typename get_reader<String, FormatTag, detail::read_and_no_convert>::type;

  reader_t reader = make_reader(file_name, tag, detail::read_and_no_convert());
  read_image(reader, img);
}

///

template <typename Reader, typename... Images>
inline void read_image(
    Reader &reader, any_image<Images...> &images,
    typename std::enable_if<
        mp11::mp_and<detail::is_dynamic_image_reader<Reader>,
                     is_format_tag<typename Reader::format_tag_t>>::value>::type
        * /*dummy*/
    = nullptr) {
  reader.apply(images);
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file      It's a device. Must satisfy is_adaptable_input_device
/// metafunction. \param images    Dynamic image (mp11::mp_list). See
/// boost::gil::dynamic_image extension. \param settings  Specifies read
/// settings depending on the image format. \throw std::ios_base::failure
template <typename Device, typename... Images, typename FormatTag>
inline void
read_image(Device &file, any_image<Images...> &images,
           image_read_settings<FormatTag> const &settings,
           typename std::enable_if<
               mp11::mp_and<detail::is_read_device<FormatTag, Device>,
                            is_format_tag<FormatTag>>::value>::type * /*dummy*/
           = nullptr) {
  using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;

  reader_t reader = make_dynamic_image_reader(file, settings);
  read_image(reader, images);
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file      It's a device. Must satisfy is_adaptable_input_device
/// metafunction. \param images    Dynamic image (mp11::mp_list). See
/// boost::gil::dynamic_image extension. \param tag       Defines the image
/// format. Must satisfy is_format_tag metafunction. \throw
/// std::ios_base::failure
template <typename Device, typename... Images, typename FormatTag>
inline void
read_image(Device &file, any_image<Images...> &images, FormatTag const &tag,
           typename std::enable_if<
               mp11::mp_and<detail::is_read_device<FormatTag, Device>,
                            is_format_tag<FormatTag>>::value>::type * /*dummy*/
           = nullptr) {
  using reader_t = typename get_dynamic_image_reader<Device, FormatTag>::type;

  reader_t reader = make_dynamic_image_reader(file, tag);
  read_image(reader, images);
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file_name File name. Must satisfy is_supported_path_spec
/// metafunction. \param images    Dynamic image (mp11::mp_list). See
/// boost::gil::dynamic_image extension. \param settings  Specifies read
/// settings depending on the image format. \throw std::ios_base::failure
template <typename String, typename... Images, typename FormatTag>
inline void read_image(
    String const &file_name, any_image<Images...> &images,
    image_read_settings<FormatTag> const &settings,
    typename std::enable_if<mp11::mp_and<detail::is_supported_path_spec<String>,
                                         is_format_tag<FormatTag>>::value>::type
        * /*dummy*/
    = nullptr) {
  using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;

  reader_t reader = make_dynamic_image_reader(file_name, settings);
  read_image(reader, images);
}

/// \brief Reads an image without conversion. Image memory is allocated.
/// \param file_name File name. Must satisfy is_supported_path_spec
/// metafunction. \param images    Dynamic image (mp11::mp_list). See
/// boost::gil::dynamic_image extension. \param tag       Defines the image
/// format. Must satisfy is_format_tag metafunction. \throw
/// std::ios_base::failure
template <typename String, typename... Images, typename FormatTag>
inline void read_image(
    String const &file_name, any_image<Images...> &images, FormatTag const &tag,
    typename std::enable_if<mp11::mp_and<detail::is_supported_path_spec<String>,
                                         is_format_tag<FormatTag>>::value>::type
        * /*dummy*/
    = nullptr) {
  using reader_t = typename get_dynamic_image_reader<String, FormatTag>::type;

  reader_t reader = make_dynamic_image_reader(file_name, tag);
  read_image(reader, images);
}

} // namespace gil
} // namespace boost

#endif

max_stars_repo_name: sdebionne/gil-reformated

max_issues_repo_name: sdebionne/gil-reformated

max_forks_repo_name: sdebionne/gil-reformated


text:
#include "pow.h"

#include <cmath>

#include <boost/test/unit_test.hpp>

using namespace boost;
using namespace std;

namespace
{
	float expf4to1(float x)
	{
		__declspec(align(16)) float v[4];
		_mm_store_ps(v, expf4(_mm_set1_ps(x)));
		return v[0];
	}

	float expf8to1(float x)
	{
		__declspec(align(32)) float v[8];
		_mm256_store_ps(v, expf8(_mm256_set1_ps(x)));
		return v[0];
	}
}

BOOST_AUTO_TEST_CASE(Expf)
{
	const float tolerance = 0.001f;

	const float args[] = { 0.01f, 0.1f, 0.5f, 1.0f, 2.0f, 5.0f };
	for (float arg : args)
	{
		BOOST_CHECK_CLOSE(expf4to1( arg), exp( arg), tolerance);
		BOOST_CHECK_CLOSE(expf4to1(-arg), exp(-arg), tolerance);
		BOOST_CHECK_CLOSE(expf8to1( arg), exp( arg), tolerance);
		BOOST_CHECK_CLOSE(expf8to1(-arg), exp(-arg), tolerance);
	}
}

BOOST_AUTO_TEST_CASE(Expf4_Fullness)
{
	const float x = 0.1f;

	__declspec(align(16)) float v[4];
	_mm_store_ps(v, expf4(_mm_set1_ps(x)));

	for (size_t i = 1; i != 4; ++i)
		BOOST_CHECK_EQUAL(v[0], v[i]);
}

BOOST_AUTO_TEST_CASE(Expf8_Fullness)
{
	const float x = 0.1f;

	__declspec(align(32)) float v[8];
	_mm256_store_ps(v, expf8(_mm256_set1_ps(x)));

	for (size_t i = 1; i != 8; ++i)
		BOOST_CHECK_EQUAL(v[0], v[i]);
}

max_stars_repo_name: don-reba/colors-visualization

max_issues_repo_name: don-reba/colors-visualization

max_forks_repo_name: don-reba/colors-visualization