test_composite_key.cpp

来自「Boost provides free peer-reviewed portab」· C++ 代码 · 共 653 行 · 第 1/2 页

CPP
653
字号
/* Boost.MultiIndex test for composite_key. * * Copyright 2003-2008 Joaquin M Lopez Munoz. * 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/libs/multi_index for library home page. */#include "test_composite_key.hpp"#include <boost/config.hpp> /* keep it first to prevent nasty warns in MSVC */#include "pre_multi_index.hpp"#include <boost/multi_index_container.hpp>#include <boost/multi_index/composite_key.hpp>#include <boost/multi_index/hashed_index.hpp>#include <boost/multi_index/member.hpp>#include <boost/multi_index/ordered_index.hpp>#include <boost/test/test_tools.hpp>using namespace boost::multi_index;using namespace boost::tuples;struct is_composite_key_result_helper{  typedef char yes;  struct no{char m[2];};  static no test(void*);  template<typename CompositeKey>  static yes test(composite_key_result<CompositeKey>*);};template<typename T>struct is_composite_key_result{  typedef is_composite_key_result_helper helper;  BOOST_STATIC_CONSTANT(bool,    value=(      sizeof(helper::test((T*)0))==      sizeof(typename helper::yes)));};template<typename CompositeKeyResult>struct composite_key_result_length{  BOOST_STATIC_CONSTANT(int,    value=boost::tuples::length<      BOOST_DEDUCED_TYPENAME       CompositeKeyResult::composite_key_type::key_extractor_tuple    >::value);};template<typename T>struct composite_object_length{  typedef typename boost::mpl::if_c<    is_composite_key_result<T>::value,    composite_key_result_length<T>,    boost::tuples::length<T>  >::type type;  BOOST_STATIC_CONSTANT(int,value=type::value);};template<typename CompositeKeyResult,typename T2>struct comparison_equal_length{  static bool is_less(const CompositeKeyResult& x,const T2& y)  {    composite_key_result_equal_to<CompositeKeyResult> eq;    composite_key_result_less<CompositeKeyResult>     lt;    composite_key_result_greater<CompositeKeyResult>  gt;#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)    std::equal_to<CompositeKeyResult> std_eq;    std::less<CompositeKeyResult>     std_lt;    std::greater<CompositeKeyResult>  std_gt;#endif    return  (x< y) && !(y< x)&&           !(x==y) && !(y==x)&&            (x!=y) &&  (y!=x)&&           !(x> y) &&  (y> x)&&           !(x>=y) &&  (y>=x)&&            (x<=y) && !(y<=x)&&          !eq(x,y) && !eq(y,x)&&           lt(x,y) && !lt(y,x)&&          !gt(x,y) &&  gt(y,x)#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)                   &&      !std_eq(x,y) && !std_eq(y,x)&&       std_lt(x,y) && !std_lt(y,x)&&      !std_gt(x,y) &&  std_gt(y,x)#endif                    ;  }  static bool is_greater(const CompositeKeyResult& x,const T2& y)  {    composite_key_result_equal_to<CompositeKeyResult> eq;    composite_key_result_less<CompositeKeyResult>     lt;    composite_key_result_greater<CompositeKeyResult>  gt;#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)    std::equal_to<CompositeKeyResult> std_eq;    std::less<CompositeKeyResult>     std_lt;    std::greater<CompositeKeyResult>  std_gt;#endif    return !(x< y) &&  (y< x)&&           !(x==y) && !(y==x)&&            (x!=y) &&  (y!=x)&&            (x> y) && !(y> x)&&            (x>=y) && !(y>=x)&&           !(x<=y) &&  (y<=x)&&          !eq(x,y) && !eq(y,x)&&          !lt(x,y) &&  lt(y,x)&&           gt(x,y) && !gt(y,x)#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)                   &&      !std_eq(x,y) && !std_eq(y,x)&&      !std_lt(x,y) &&  std_lt(y,x)&&       std_gt(x,y) && !std_gt(y,x)#endif                    ;  }  static bool is_equiv(const CompositeKeyResult& x,const T2& y)  {    composite_key_result_equal_to<CompositeKeyResult> eq;    composite_key_result_less<CompositeKeyResult>     lt;    composite_key_result_greater<CompositeKeyResult>  gt;#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)    std::equal_to<CompositeKeyResult> std_eq;    std::less<CompositeKeyResult>     std_lt;    std::greater<CompositeKeyResult>  std_gt;#endif    return !(x< y) && !(y< x)&&            (x==y) &&  (y==x)&&           !(x!=y) && !(y!=x)&&           !(x> y) && !(y> x)&&            (x>=y) &&  (y>=x)&&            (x<=y) &&  (y<=x)&&           eq(x,y) &&  eq(y,x)&&          !lt(x,y) && !lt(y,x)&&          !gt(x,y) && !gt(y,x)#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)                   &&       std_eq(x,y) &&  std_eq(y,x)&&      !std_lt(x,y) && !std_lt(y,x)&&      !std_gt(x,y) && !std_gt(y,x)#endif                    ;  }};template<typename CompositeKeyResult,typename T2>struct comparison_different_length{  static bool is_less(const CompositeKeyResult& x,const T2& y)  {    composite_key_result_less<CompositeKeyResult>    lt;    composite_key_result_greater<CompositeKeyResult> gt;#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)    std::less<CompositeKeyResult>    std_lt;    std::greater<CompositeKeyResult> std_gt;#endif    return  (x< y) && !(y< x)&&           !(x> y) &&  (y> x)&&           !(x>=y) &&  (y>=x)&&            (x<=y) && !(y<=x)&&           lt(x,y) && !lt(y,x)&&          !gt(x,y) &&  gt(y,x)          #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)                   &&       std_lt(x,y) && !std_lt(y,x)&&      !std_gt(x,y) &&  std_gt(y,x)#endif                    ;  }  static bool is_greater(const CompositeKeyResult& x,const T2& y)  {    composite_key_result_less<CompositeKeyResult>    lt;    composite_key_result_greater<CompositeKeyResult> gt;#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)    std::less<CompositeKeyResult>    std_lt;    std::greater<CompositeKeyResult> std_gt;#endif    return !(x< y) &&  (y< x)&&            (x> y) && !(y> x)&&            (x>=y) && !(y>=x)&&           !(x<=y) &&  (y<=x)&&          !lt(x,y) &&  lt(y,x)&&           gt(x,y) && !gt(y,x)#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)                   &&      !std_lt(x,y) && std_lt(y,x)&&       std_gt(x,y) && !std_gt(y,x)#endif                    ;  }  static bool is_equiv(const CompositeKeyResult& x,const T2& y)  {    composite_key_result_less<CompositeKeyResult>    lt;    composite_key_result_greater<CompositeKeyResult> gt;#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)    std::less<CompositeKeyResult>    std_lt;    std::greater<CompositeKeyResult> std_gt;#endif    return !(x< y) && !(y< x)&&           !(x> y) && !(y> x)&&            (x>=y) &&  (y>=x)&&            (x<=y) &&  (y<=x)&&          !lt(x,y) && !lt(y,x)&&          !gt(x,y) && !gt(y,x)#if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)                   &&      !std_lt(x,y) && !std_lt(y,x)&&      !std_gt(x,y) && !std_gt(y,x)#endif                    ;  }};template<typename CompositeKeyResult,typename T2>struct comparison_helper:  boost::mpl::if_c<    composite_key_result_length<CompositeKeyResult>::value==      composite_object_length<T2>::value,    comparison_equal_length<CompositeKeyResult,T2>,    comparison_different_length<CompositeKeyResult,T2>  >::type{};template<typename CompositeKeyResult,typename T2>static bool is_less(const CompositeKeyResult& x,const T2& y){  return comparison_helper<CompositeKeyResult,T2>::is_less(x,y);}template<typename CompositeKeyResult,typename T2>static bool is_greater(const CompositeKeyResult& x,const T2& y){  return comparison_helper<CompositeKeyResult,T2>::is_greater(x,y);}template<typename CompositeKeyResult,typename T2>static bool is_equiv(const CompositeKeyResult& x,const T2& y){  return comparison_helper<CompositeKeyResult,T2>::is_equiv(x,y);}template<typename T1,typename T2,typename Compare>static bool is_less(const T1& x,const T2& y,const Compare& c){  return c(x,y)&&!c(y,x);}template<typename T1,typename T2,typename Compare>static bool is_greater(const T1& x,const T2& y,const Compare& c){  return c(y,x)&&!c(x,y);}template<typename T1,typename T2,typename Compare>static bool is_equiv(const T1& x,const T2& y,const Compare& c){  return !c(x,y)&&!c(y,x);}template<typename T1,typename T2,typename Compare,typename Equiv>static bool is_less(  const T1& x,const T2& y,const Compare& c,const Equiv& eq){  return c(x,y)&&!c(y,x)&&!eq(x,y)&&!eq(y,x);}template<typename T1,typename T2,typename Compare,typename Equiv>static bool is_greater(  const T1& x,const T2& y,const Compare& c,const Equiv& eq){  return c(y,x)&&!c(x,y)&&!eq(x,y)&&!eq(y,x);}template<typename T1,typename T2,typename Compare,typename Equiv>static bool is_equiv(  const T1& x,const T2& y,const Compare& c,const Equiv& eq){  return !c(x,y)&&!c(y,x)&&eq(x,y)&&eq(y,x);}struct xyz{  xyz(int x_=0,int y_=0,int z_=0):x(x_),y(y_),z(z_){}  int  x;  int  y;  int  z;};

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?