当前位置: 首页>>代码示例>>C++>>正文


C++ From类代码示例

本文整理汇总了C++中From的典型用法代码示例。如果您正苦于以下问题:C++ From类的具体用法?C++ From怎么用?C++ From使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了From类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: cast

    static inline
    asio::ip::tcp::endpoint
    cast(const From& endpoint) {
        switch (endpoint.protocol().family()) {
        case AF_INET: {
            const sockaddr_in* addr = reinterpret_cast<const sockaddr_in*>(endpoint.data());
            asio::ip::address_v4::bytes_type array;
            std::copy((char*)&addr->sin_addr, (char*)&addr->sin_addr + array.size(), array.begin());
            asio::ip::address_v4 address(array);
            return asio::ip::tcp::endpoint(
                       address,
                       asio::detail::socket_ops::network_to_host_short(addr->sin_port)
                   );
        }
        case AF_INET6: {
            const sockaddr_in6* addrv6 = reinterpret_cast<const sockaddr_in6*>(endpoint.data());
            asio::ip::address_v6::bytes_type array;
            std::copy((char*)&addrv6->sin6_addr, (char*)&addrv6->sin6_addr + array.size(), array.begin());
            asio::ip::address_v6 address(array, addrv6->sin6_scope_id);
            return asio::ip::tcp::endpoint(
                       address,
                       asio::detail::socket_ops::network_to_host_short(addrv6->sin6_port)
                   );
        }
        default:
            BOOST_ASSERT(false);
        };

        return asio::ip::tcp::endpoint();
    }
开发者ID:arssher,项目名称:cocaine-core,代码行数:30,代码来源:net.hpp

示例2: move

bool move(To& to, From& from) {
    if (CFGetTypeID(from.c_obj()) == To::type_id()) {
        to.reset(reinterpret_cast<typename To::type>(from.release()));
        return true;
    }
    return false;
}
开发者ID:xuxiaojing,项目名称:antares,代码行数:7,代码来源:core-foundation.hpp

示例3: operator

 To operator ()(From &arr) const
 {
     typename remove_const<To>::type res(arr.size());
     for(std::size_t i = 0, size = arr.size(); i != size; ++i)
     {
         res[i] = numeric::promote<typename To::value_type>(arr[i]);
     }
     return res;
 }
开发者ID:CustomOrthopaedics,项目名称:OTS-Boost,代码行数:9,代码来源:vector.hpp

示例4: get_block

 std::vector< char > get_block(
     std::vector<char>::const_iterator prefix_begin, std::vector<char>::const_iterator prefix_end,
     const From &from_string, typename From::size_type head_pos ) {
     typename From::size_type block_size = std::min( from_string.size() * sizeof( typename From::value_type ) - head_pos, block_size );
     std::vector< char > block( prefix_begin, prefix_end );
     block.resize( block.size() + block_size );
     std::vector< char >::iterator output_head = block.begin();
     std::advance( output_head, std::distance( prefix_begin, prefix_end ) );
     std::copy( reinterpret_cast<const char*>( from_string.c_str() ) + head_pos, reinterpret_cast<const char*>( from_string.c_str() ) + head_pos + block_size, output_head );
     return block;
 }
开发者ID:Fadis,项目名称:iconvpp,代码行数:11,代码来源:iconv++.hpp

示例5: test_convert_imp

void test_convert_imp(boost::mpl::int_<number_kind_integer> const&, boost::mpl::int_<number_kind_integer> const&)
{
   int bits_wanted = (std::min)((std::min)(std::numeric_limits<From>::digits, std::numeric_limits<To>::digits), 2000);

   for(unsigned i = 0; i < 100; ++i)
   {
      From from = generate_random<From>(bits_wanted);
      To t1(from);
      To t2 = from.template convert_to<To>();
      BOOST_CHECK_EQUAL(from.str(), t1.str());
      BOOST_CHECK_EQUAL(from.str(), t2.str());
      test_convert_neg_int<From, To>(from, boost::mpl::bool_<std::numeric_limits<From>::is_signed && std::numeric_limits<To>::is_signed>());
   }
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:14,代码来源:test_convert_from_mpz_int.cpp

示例6: test_convert_neg_rat

void test_convert_neg_rat(From from, const boost::mpl::true_&)
{
   from = -from;
   To t3(from);
   To t4 = from.template convert_to<To>();
   BOOST_CHECK_EQUAL(from.str(), numerator(t3).str());
   BOOST_CHECK_EQUAL(from.str(), numerator(t4).str());
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:8,代码来源:test_convert_from_mpz_int.cpp

示例7: test_convert_neg_int

void test_convert_neg_int(From from, const boost::mpl::true_&)
{
   from = -from;
   To t3(from);
   To t4 = from.template convert_to<To>();
   BOOST_CHECK_EQUAL(from.str(), t3.str());
   BOOST_CHECK_EQUAL(from.str(), t4.str());
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:8,代码来源:test_convert_from_mpz_int.cpp

示例8: test_convert_neg_float

void test_convert_neg_float(From from, const boost::mpl::true_&)
{
   from = -from;
   To t3(from);
   To t4 = from.template convert_to<To>();
   To check(from.str() + ".0");
   BOOST_CHECK_EQUAL(t3, check);
   BOOST_CHECK_EQUAL(t4, check);
}
开发者ID:LocutusOfBorg,项目名称:poedit,代码行数:9,代码来源:test_convert_from_mpz_int.cpp

示例9: operator

    To operator()( const From &from_string ) {
        To to_string;
        typename From::size_type head_pos = 0;
        std::vector< char > partial_sequence;
        while( 1 ) {
            const std::vector< char > input_block = get_block( partial_sequence.begin(), partial_sequence.end(), from_string, head_pos );
            head_pos += input_block.size() - partial_sequence.size();
            const std::pair< std::vector< char >, std::vector< char > > output_block = convert_block< block_size >( cd, input_block );
            const To temp = set_block( output_block.first );
            partial_sequence = output_block.second;
            to_string += temp;
            if( head_pos == from_string.size() * sizeof( typename From::value_type ) )
                break;

        }
        return to_string;
    }
开发者ID:Fadis,项目名称:iconvpp,代码行数:17,代码来源:iconv++.hpp

示例10: generic_interconvert

void generic_interconvert(To& to, const From& from, const mpl::int_<number_kind_floating_point>& /*to_type*/, const mpl::int_<number_kind_floating_point>& /*from_type*/)
{
#ifdef BOOST_MSVC
#pragma warning(push)
#pragma warning(disable:4127)
#endif
   //
   // The code here only works when the radix of "From" is 2, we could try shifting by other
   // radixes but it would complicate things.... use a string conversion when the radix is other
   // than 2:
   //
   if(std::numeric_limits<number<From> >::radix != 2)
   {
      to = from.str(0, std::ios_base::fmtflags()).c_str();
      return;
   }


   typedef typename canonical<unsigned char, To>::type ui_type;

   using default_ops::eval_fpclassify;
   using default_ops::eval_add;
   using default_ops::eval_subtract;
   using default_ops::eval_convert_to;

   //
   // First classify the input, then handle the special cases:
   //
   int c = eval_fpclassify(from);

   if(c == FP_ZERO)
   {
      to = ui_type(0);
      return;
   }
   else if(c == FP_NAN)
   {
      to = "nan";
      return;
   }
   else if(c == FP_INFINITE)
   {
      to = "inf";
      if(eval_get_sign(from) < 0)
         to.negate();
      return;
   }

   typename From::exponent_type e;
   From f, term;
   to = ui_type(0);

   eval_frexp(f, from, &e);

   static const int shift = std::numeric_limits<boost::intmax_t>::digits - 1;

   while(!eval_is_zero(f))
   {
      // extract int sized bits from f:
      eval_ldexp(f, f, shift);
      eval_floor(term, f);
      e -= shift;
      eval_ldexp(to, to, shift);
      typename boost::multiprecision::detail::canonical<boost::intmax_t, To>::type ll;
      eval_convert_to(&ll, term);
      eval_add(to, ll);
      eval_subtract(f, term);
   }
   typedef typename To::exponent_type to_exponent;
   if((e > (std::numeric_limits<to_exponent>::max)()) || (e < (std::numeric_limits<to_exponent>::min)()))
   {
      to = "inf";
      if(eval_get_sign(from) < 0)
         to.negate();
      return;
   }
   eval_ldexp(to, to, static_cast<to_exponent>(e));
#ifdef BOOST_MSVC
#pragma warning(pop)
#endif
}
开发者ID:1ack,项目名称:Impala,代码行数:81,代码来源:generic_interconvert.hpp

示例11: duration_cast

To duration_cast(From const& dt) {
  return To(From::period::num * dt.count(), From::period::den);
}
开发者ID:michail-peterlis,项目名称:prosto,代码行数:3,代码来源:duration.hpp

示例12: cast

To cast(From from) {
    if (CFGetTypeID(from.c_obj()) == To::type_id()) {
        return To(reinterpret_cast<typename To::type>(from.release()));
    }
    return nullptr;
}
开发者ID:SupinfoGameDev,项目名称:antares,代码行数:6,代码来源:core-foundation.hpp

示例13: vchar2string

void vchar2string(To& t,From& f)
{
	t.assign(f.begin(),f.end());
}
开发者ID:iloveghq,项目名称:Bitest,代码行数:4,代码来源:SorAssist.cpp

示例14: operator

 To operator()(const From& x) const {
   return x.get();
 }
开发者ID:bpxeax,项目名称:actor-framework,代码行数:3,代码来源:actor_cast.hpp

示例15: move_to

 // Pass by reference for lvalue of 'move_ptr'.
 // Also note 'auto_ptr' isn't copy-initializable from one which has
 // a different 'element_type'. See http://tinyurl.com/yo8a7w (defect report #84).
 template< class To, class From > inline
 To move_to(From& from)
 {
     return To(from.release());
 }
开发者ID:fpelliccioni,项目名称:pstade,代码行数:8,代码来源:initial_ptrs.hpp


注:本文中的From类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。