Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-08-06 09:38:32

0001 // -*- C++ -*-
0002 //
0003 // Triplet.h is a part of ThePEG - Toolkit for HEP Event Generation
0004 // Copyright (C) 1999-2019 Leif Lonnblad
0005 //
0006 // ThePEG is licenced under version 3 of the GPL, see COPYING for details.
0007 // Please respect the MCnet academic guidelines, see GUIDELINES for details.
0008 //
0009 #ifndef ThePEG_Triplet_H
0010 #define ThePEG_Triplet_H
0011 
0012 #include "ThePEG/Config/ThePEG.h"
0013 
0014 namespace ThePEG {
0015 
0016 /**
0017  * The Triplet class represents a general triplet of objects
0018  * completely analogous to <code>std::pair</code>.
0019  */
0020 template <typename T1, typename T2, typename T3>
0021 struct Triplet {
0022 
0023   /** The type of the first member. */
0024   typedef T1 first_type;
0025   /** The type of the second member. */
0026   typedef T2 second_type;
0027   /** The type of the third member. */
0028   typedef T3 third_type;
0029 
0030   /** The first member. */
0031   T1 first;
0032   /** The second member. */
0033   T2 second;
0034   /** The third member. */
0035   T3 third;
0036 
0037   /** Default construcotr. */
0038   Triplet() : first(T1()), second(T2()), third(T3()) {}
0039 
0040   /** Constructor specifying the three members. */
0041   Triplet(const T1 & t1, const T2 & t2, const T3 & t3)
0042     : first(t1), second(t2), third(t3) {}
0043 
0044   /** Copy constructor. */
0045   Triplet(const Triplet<T1,T2,T3> & t)
0046     : first(t.first), second(t.second), third(t.third) {}
0047 
0048   /** Copy constructor from other Triplet type. */
0049   template <typename U1, typename U2, typename U3>
0050   Triplet(const Triplet<U1,U2,U3> & u)
0051     : first(u.first), second(u.second), third(u.third) {}
0052 
0053   /** Test for equality. */
0054   bool operator==(const Triplet<T1,T2,T3> & t) const {
0055     return first == t.first && second == t.second && third == t.third;
0056   }
0057 
0058   /** Test for ordering.
0059    * @return <code>first < t.first || ( * !(t.first < first) && (
0060    * second < t.second || ( !(t.second < second) && third < t.third
0061    * )))</code> */
0062   bool operator<(const Triplet<T1,T2,T3> & t) const {
0063     return first < t.first ||
0064       ( !(t.first < first) && 
0065     ( second < t.second ||
0066       ( !(t.second < second) && third < t.third )));
0067   }
0068 };
0069 
0070 /** Helper function returning a Triplet with template parameters
0071  *  determined by the arguments. */
0072 template <typename T1, typename T2, typename T3>
0073 inline Triplet<T1,T2,T3>
0074 makeTriplet (const T1 & t1, const T2 & t2, const T3 & t3)
0075 {
0076   return Triplet<T1,T2,T3>(t1, t2, t3);
0077 }
0078 
0079 /** Output a Triplet to a stream. */
0080 template <typename OStream, typename T1, typename T2, typename T3>
0081 OStream & operator<<(OStream & os, const Triplet<T1,T2,T3> & t) {
0082   return os << t.first << t.second << t.third;
0083 }
0084 
0085 /** Input a Triplet from a stream. */
0086 template <typename IStream, typename T1, typename T2, typename T3>
0087 IStream & operator>>(IStream & is, Triplet<T1,T2,T3> & t) {
0088   return is >> t.first >> t.second >> t.third;
0089 }
0090 
0091 }
0092 
0093 #endif /* ThePEG_Triplet_H */