Page Menu
Home
HEPForge
Search
Configure Global Search
Log In
Files
F19250993
CompareByIndex.hh
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Size
1 KB
Referenced Files
None
Subscribers
None
CompareByIndex.hh
View Options
#ifndef NPSTAT_COMPAREBYINDEX_HH_
#define NPSTAT_COMPAREBYINDEX_HH_
/*!
// \file CompareByIndex.hh
//
// \brief Compare subscriptable objects (e.g., vectors) by their k-th element
//
// Author: I. Volobouev
//
// March 2010
*/
namespace
npstat
{
/**
// Comparison functor for classes which support subscripting and for
// pointers to such classes. To be used with std::sort and such.
*/
template
<
typename
T
>
class
LessByIndex
{
public
:
/** Constructor takes the index of the element to be compared */
inline
explicit
LessByIndex
(
const
unsigned
i
)
:
i_
(
i
)
{}
inline
bool
operator
()(
const
T
&
x
,
const
T
&
y
)
const
{
return
x
[
i_
]
<
y
[
i_
];}
inline
bool
operator
()(
const
T
*
x
,
const
T
*
y
)
const
{
return
(
*
x
)[
i_
]
<
(
*
y
)[
i_
];}
private
:
LessByIndex
();
unsigned
i_
;
};
/**
// Comparison functor for classes which support subscripting and for
// pointers to such classes. To be used with std::sort and such.
*/
template
<
typename
T
>
class
GreaterByIndex
{
public
:
/** Constructor takes the index of the element to be compared */
inline
explicit
GreaterByIndex
(
const
unsigned
i
)
:
i_
(
i
)
{}
inline
bool
operator
()(
const
T
&
x
,
const
T
&
y
)
const
{
return
y
[
i_
]
<
x
[
i_
];}
inline
bool
operator
()(
const
T
*
x
,
const
T
*
y
)
const
{
return
(
*
y
)[
i_
]
<
(
*
x
)[
i_
];}
private
:
GreaterByIndex
();
unsigned
i_
;
};
}
#endif
// NPSTAT_COMPAREBYINDEX_HH_
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Tue, Sep 30, 5:46 AM (15 h, 11 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
6548413
Default Alt Text
CompareByIndex.hh (1 KB)
Attached To
Mode
rNPSTATSVN npstatsvn
Attached
Detach File
Event Timeline
Log In to Comment