Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
C
capnproto
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
capnproto
Commits
0c3ec192
Commit
0c3ec192
authored
Mar 30, 2017
by
Kenton Varda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make kj::range() not get confused when the inputs have different types.
parent
f1320274
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
17 deletions
+14
-17
common.h
c++/src/kj/common.h
+14
-17
No files found.
c++/src/kj/common.h
View file @
0c3ec192
...
...
@@ -493,30 +493,22 @@ template<typename T> constexpr T cp(T& t) noexcept { return t; }
template
<
typename
T
>
constexpr
T
cp
(
const
T
&
t
)
noexcept
{
return
t
;
}
// Useful to force a copy, particularly to pass into a function that expects T&&.
template
<
typename
T
,
typename
U
,
bool
takeT
>
struct
MinType_
;
template
<
typename
T
,
typename
U
>
struct
MinType_
<
T
,
U
,
true
>
{
typedef
T
Type
;
};
template
<
typename
T
,
typename
U
>
struct
MinType_
<
T
,
U
,
false
>
{
typedef
U
Type
;
};
template
<
typename
T
,
typename
U
,
bool
takeT
,
bool
uOK
=
true
>
struct
ChooseType_
;
template
<
typename
T
,
typename
U
>
struct
ChooseType_
<
T
,
U
,
true
,
true
>
{
typedef
T
Type
;
};
template
<
typename
T
,
typename
U
>
struct
ChooseType_
<
T
,
U
,
true
,
false
>
{
typedef
T
Type
;
};
template
<
typename
T
,
typename
U
>
struct
ChooseType_
<
T
,
U
,
false
,
true
>
{
typedef
U
Type
;
};
template
<
typename
T
,
typename
U
>
using
MinType
=
typename
MinType_
<
T
,
U
,
sizeof
(
T
)
<=
sizeof
(
U
)
>::
Type
;
// Resolves to the smaller of the two input types.
using
WiderType
=
typename
ChooseType_
<
T
,
U
,
sizeof
(
T
)
>=
sizeof
(
U
)
>::
Type
;
template
<
typename
T
,
typename
U
>
inline
constexpr
auto
min
(
T
&&
a
,
U
&&
b
)
->
Min
Type
<
Decay
<
T
>
,
Decay
<
U
>>
{
return
a
<
b
?
MinType
<
Decay
<
T
>
,
Decay
<
U
>>
(
a
)
:
Min
Type
<
Decay
<
T
>
,
Decay
<
U
>>
(
b
);
inline
constexpr
auto
min
(
T
&&
a
,
U
&&
b
)
->
Wider
Type
<
Decay
<
T
>
,
Decay
<
U
>>
{
return
a
<
b
?
WiderType
<
Decay
<
T
>
,
Decay
<
U
>>
(
a
)
:
Wider
Type
<
Decay
<
T
>
,
Decay
<
U
>>
(
b
);
}
template
<
typename
T
,
typename
U
,
bool
takeT
>
struct
MaxType_
;
template
<
typename
T
,
typename
U
>
struct
MaxType_
<
T
,
U
,
true
>
{
typedef
T
Type
;
};
template
<
typename
T
,
typename
U
>
struct
MaxType_
<
T
,
U
,
false
>
{
typedef
U
Type
;
};
template
<
typename
T
,
typename
U
>
using
MaxType
=
typename
MaxType_
<
T
,
U
,
sizeof
(
T
)
>=
sizeof
(
U
)
>::
Type
;
// Resolves to the larger of the two input types.
template
<
typename
T
,
typename
U
>
inline
constexpr
auto
max
(
T
&&
a
,
U
&&
b
)
->
Max
Type
<
Decay
<
T
>
,
Decay
<
U
>>
{
return
a
>
b
?
MaxType
<
Decay
<
T
>
,
Decay
<
U
>>
(
a
)
:
Max
Type
<
Decay
<
T
>
,
Decay
<
U
>>
(
b
);
inline
constexpr
auto
max
(
T
&&
a
,
U
&&
b
)
->
Wider
Type
<
Decay
<
T
>
,
Decay
<
U
>>
{
return
a
>
b
?
WiderType
<
Decay
<
T
>
,
Decay
<
U
>>
(
a
)
:
Wider
Type
<
Decay
<
T
>
,
Decay
<
U
>>
(
b
);
}
template
<
typename
T
,
size_t
s
>
...
...
@@ -683,6 +675,11 @@ private:
T
end_
;
};
template
<
typename
T
,
typename
U
>
inline
constexpr
Range
<
WiderType
<
Decay
<
T
>
,
Decay
<
U
>>>
range
(
T
begin
,
U
end
)
{
return
Range
<
WiderType
<
Decay
<
T
>
,
Decay
<
U
>>>
(
begin
,
end
);
}
template
<
typename
T
>
inline
constexpr
Range
<
Decay
<
T
>>
range
(
T
begin
,
T
end
)
{
return
Range
<
Decay
<
T
>>
(
begin
,
end
);
}
// Returns a fake iterable container containing all values of T from `begin` (inclusive) to `end`
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment