Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitf734b3f

Browse files
committed
SFINAE-ization of Tag Dispatch System
Thanks to Thomas Heller for the tips on the dramatic reduction of compile times in the cpp-netlibimplementation, this commit is now generally considered a major compile-time enhancement overprevious versions/iterations of the library. In this particular case the compile time reductionis actually significant just by using SFINAE and partial specialization over (ab)use of theBoost.MPL facilities.
1 parentd8f04ea commitf734b3f

26 files changed

+262
-254
lines changed

‎boost/network/protocol/http/message/traits/version.hpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -20,23 +20,32 @@ namespace boost { namespace network { namespace http {
2020
template<classTag>
2121
structunsupported_tag;
2222

23-
template<classMessage>
23+
template<classMessage,classEnable =void>
2424
structversion
25-
: mpl::if_<
26-
is_async<typename Message::tag>,
27-
boost::shared_future<typename string<typename Message::tag>::type>,
28-
typename mpl::if_<
25+
{
26+
typedef unsupported_tag<typename Message::tag> type;
27+
};
28+
29+
template<classMessage>
30+
structversion<Message,typename enable_if<is_async<typename Message::tag> >::type>
31+
{
32+
typedef boost::shared_future<typename string<typename Message::tag>::type> type;
33+
};
34+
35+
template<classMessage>
36+
structversion<Message,
37+
typename enable_if<
2938
mpl::or_<
3039
is_sync<typename Message::tag>,
31-
is_same<typename Message::tag, tags::default_string>,
32-
is_same<typename Message::tag, tags::default_wstring>
33-
>,
34-
typename string<typename Message::tag>::type,
35-
unsupported_tag<typename Message::tag>
36-
>::type
37-
>
38-
{};
39-
40+
is_default_string<typename Message::tag>,
41+
is_default_wstring<typename Message::tag>
42+
>
43+
>::type
44+
>
45+
{
46+
typedeftypename string<typename Message::tag>::type type;
47+
};
48+
4049
}/* traits*/
4150

4251
}/* http*/

‎boost/network/protocol/http/support/client_or_server.hpp

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,27 @@
1111
#include<boost/mpl/if.hpp>
1212

1313
namespaceboost {namespacenetwork {namespacehttp {
14-
14+
1515
template<classTag>
16-
structclient_or_server :
17-
mpl::if_<
18-
is_server<Tag>,
19-
tags::server,
20-
typename mpl::if_<
21-
is_client<Tag>,
22-
tags::client,
23-
unsupported_tag<Tag>
24-
>::type
25-
>
26-
{};
27-
16+
structunsupported_tag;
17+
18+
template<classTag,classEnable =void>
19+
structclient_or_server
20+
{
21+
typedef unsupported_tag<Tag> type;
22+
};
23+
24+
template<classTag>
25+
structclient_or_server<Tag,typename enable_if<is_server<Tag> >::type>
26+
{
27+
typedef tags::server type;
28+
};
29+
30+
template<classTag>
31+
structclient_or_server<Tag,typename enable_if<is_client<Tag> >::type>
32+
{
33+
typedef tags::client type;
34+
};
2835

2936
}/* http*/
3037

‎boost/network/protocol/http/support/is_client.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include<boost/network/protocol/http/tags.hpp>
10-
#include<boost/type_traits/is_base_of.hpp>
10+
#include<boost/utility/enable_if.hpp>
1111

1212
namespaceboost {namespacenetwork {namespacehttp {
1313

14+
template<classTag,classEnable =void>
15+
structis_client : mpl::false_ {};
16+
1417
template<classTag>
15-
structis_client :
16-
is_base_of<
17-
tags::client,
18-
Tag
19-
>
20-
{};
18+
structis_client<Tag,typename enable_if<typename Tag::is_client>::type> : mpl::true_ {};
2119

2220
}/* http*/
2321

‎boost/network/protocol/http/support/is_http.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,16 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include<boost/network/protocol/http/tags.hpp>
10-
#include<boost/type_traits/is_base_of.hpp>
10+
#include<boost/utility/enable_if.hpp>
1111

1212
namespaceboost {namespacenetwork {namespacehttp {
1313

14+
template<classTag,classEnable =void>
15+
structis_http : mpl::false_ {};
16+
1417
template<classTag>
15-
structis_http :
16-
is_base_of<
17-
tags::http,
18-
Tag
19-
>
20-
{};
21-
18+
structis_http<Tag,typename enable_if<typename Tag::is_http>::type> : mpl::true_ {};
19+
2220
}// namespace http
2321

2422
}// namespace network

‎boost/network/protocol/http/support/is_keepalive.hpp

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,19 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include<boost/network/protocol/http/tags.hpp>
10-
#include<boost/type_traits/is_base_of.hpp>
10+
#include<boost/utility/enable_if.hpp>
1111

1212
namespaceboost {namespacenetwork {namespacehttp {
1313

1414
template<classTag>
1515
structunsupported_tag;
1616

17+
template<classTag,classEnable =void>
18+
structis_keepalive : mpl::false_ {};
19+
1720
template<classTag>
18-
structis_keepalive :
19-
is_base_of<
20-
http::tags::keepalive
21-
, Tag
22-
>
23-
{};
24-
21+
structis_keepalive<Tag,typename enable_if<typename Tag::is_keepalive>::type> : mpl::true_ {};
22+
2523
}/* http*/
2624

2725
}/* network*/

‎boost/network/protocol/http/support/is_server.hpp

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include<boost/network/protocol/http/tags.hpp>
10-
#include<boost/type_traits/is_base_of.hpp>
10+
#include<boost/utility/enable_if.hpp>
1111

1212
namespaceboost {namespacenetwork {namespacehttp {
1313

14+
template<classTag,classEnable =void>
15+
structis_server : mpl::false_ {};
16+
1417
template<classTag>
15-
structis_server :
16-
is_base_of<
17-
tags::server,
18-
Tag
19-
>
20-
{};
18+
structis_server<Tag,typename enable_if<typename Tag::is_server>::type> : mpl::true_ {};
2119

2220
}/* http*/
2321

‎boost/network/protocol/http/support/is_simple.hpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,16 @@
77
// http://www.boost.org/LICENSE_1_0.txt)
88

99
#include<boost/network/protocol/http/tags.hpp>
10-
#include<boost/type_traits/is_base_of.hpp>
10+
#include<boost/utility/enable_if.hpp>
1111

1212
namespaceboost {namespacenetwork {namespacehttp {
1313

14+
template<classTag,classEnable =void>
15+
structis_simple : mpl::false_ {};
16+
1417
template<classTag>
15-
structunsupported_tag;
16-
17-
template<classTag>
18-
structis_simple :
19-
is_base_of<
20-
tags::simple
21-
, Tag
22-
>
23-
{};
24-
18+
structis_simple<Tag,typename enable_if<typename Tag::is_simple>::type> : mpl::true_ {};
19+
2520
}/* http*/
2621

2722
}/* network*/

‎boost/network/protocol/http/tags.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,11 @@
1010

1111
namespaceboost {namespacenetwork {namespacehttp {namespacetags {
1212

13-
structhttp{};
14-
structkeepalive{};
15-
structsimple{};
16-
structserver{};
17-
structclient{};
13+
structhttp {typedef mpl::true_::type is_http;};
14+
structkeepalive {typedef mpl::true_::type is_keepalive;};
15+
structsimple {typedef mpl::true_::type is_simple;};
16+
structserver {typedef mpl::true_::type is_server;};
17+
structclient {typedef mpl::true_::type is_client;};
1818

1919
usingnamespaceboost::network::tags;
2020

‎boost/network/protocol/http/traits/connection_policy.hpp

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,37 @@
1313
#include<boost/network/protocol/http/support/is_simple.hpp>
1414
#include<boost/network/protocol/http/support/is_keepalive.hpp>
1515
#include<boost/network/support/is_async.hpp>
16+
#include<boost/mpl/and.hpp>
17+
#include<boost/mpl/not.hpp>
1618

1719
namespaceboost {namespacenetwork {namespacehttp {
1820

1921
template<classTag>
2022
structunsupported_tag;
2123

24+
template<classTag,unsigned version_major,unsigned version_minor,classEnable =void>
25+
structconnection_policy
26+
{
27+
typedef unsupported_tag<Tag> type;
28+
};
29+
2230
template<classTag,unsigned version_major,unsigned version_minor>
23-
structconnection_policy :
24-
mpl::if_<
25-
is_async<Tag>,
26-
async_connection_policy<Tag,version_major,version_minor>,
27-
typename mpl::if_<
28-
is_simple<Tag>,
29-
simple_connection_policy<Tag,version_major,version_minor>,
30-
typename mpl::if_<
31-
is_keepalive<Tag>,
32-
pooled_connection_policy<Tag,version_major,version_minor>,
33-
unsupported_tag<Tag>
34-
>::type
35-
>::type
36-
>
37-
{};
31+
structconnection_policy<Tag, version_major, version_minor,typename enable_if<is_async<Tag> >::type>
32+
{
33+
typedef async_connection_policy<Tag, version_major, version_minor> type;
34+
};
35+
36+
template<classTag,unsigned version_major,unsigned version_minor>
37+
structconnection_policy<Tag, version_major, version_minor,typename enable_if<mpl::and_<is_simple<Tag>, mpl::not_<is_async<Tag> > > >::type>
38+
{
39+
typedef simple_connection_policy<Tag, version_major, version_minor> type;
40+
};
41+
42+
template<classTag,unsigned version_major,unsigned version_minor>
43+
structconnection_policy<Tag, version_major, version_minor,typename enable_if<mpl::and_<is_keepalive<Tag>, mpl::not_<is_async<Tag> > > >::type>
44+
{
45+
typedef pooled_connection_policy<Tag, version_major, version_minor> type;
46+
};
3847

3948
}// namespace http
4049

‎boost/network/support/is_async.hpp

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,15 @@
88
// http://www.boost.org/LICENSE_1_0.txt)
99

1010
#include<boost/network/tags.hpp>
11-
#include<boost/mpl/if.hpp>
12-
#include<boost/type_traits/is_base_of.hpp>
11+
#include<boost/utility/enable_if.hpp>
1312

1413
namespaceboost {namespacenetwork {
1514

15+
template<classTag,classEnable =void>
16+
structis_async : mpl::false_ {};
17+
1618
template<classTag>
17-
structis_async :
18-
is_base_of<
19-
tags::async,
20-
Tag
21-
>
22-
{};
19+
structis_async<Tag,typename enable_if<typename Tag::is_async>::type> : mpl::true_ {};
2320

2421
}// namespace network
2522

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp