1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689
|
// Copyright Daniel Wallin 2006.
// 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)
#include <boost/parameter/preprocessor.hpp>
#include <boost/parameter/binding.hpp>
#include <boost/parameter/config.hpp>
#include "basics.hpp"
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
#include <type_traits>
#else
#include <boost/mpl/bool.hpp>
#include <boost/mpl/if.hpp>
#include <boost/type_traits/is_same.hpp>
#endif
namespace test {
BOOST_PARAMETER_BASIC_FUNCTION((int), f, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *)
(index, (int))
)
)
{
typedef typename boost::parameter::binding<
Args,test::tag::index,int&
>::type index_type;
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
static_assert(
std::is_same<index_type,int&>::value
, "index_type == int&"
);
#else
BOOST_MPL_ASSERT((
typename boost::mpl::if_<
boost::is_same<index_type,int&>
, boost::mpl::true_
, boost::mpl::false_
>::type
));
#endif
args[test::_tester](
args[test::_name]
, args[test::_value | 1.f]
, args[test::_index | 2]
);
return 1;
}
} // namespace test
#include <boost/parameter/value_type.hpp>
#if !defined(BOOST_PARAMETER_CAN_USE_MP11)
#include <boost/type_traits/remove_const.hpp>
#endif
namespace test {
BOOST_PARAMETER_BASIC_FUNCTION((int), g, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *)
(index, (int))
)
)
{
typedef typename boost::parameter::value_type<
Args,test::tag::index,int
>::type index_type;
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
static_assert(
std::is_same<
typename std::remove_const<index_type>::type
, int
>::value
, "remove_const<index_type>::type == int"
);
#else
BOOST_MPL_ASSERT((
typename boost::mpl::if_<
boost::is_same<
typename boost::remove_const<index_type>::type
, int
>
, boost::mpl::true_
, boost::mpl::false_
>::type
));
#endif
args[test::_tester](
args[test::_name]
, args[test::_value | 1.f]
, args[test::_index | 2]
);
return 1;
}
} // namespace test
#if !defined(BOOST_PARAMETER_CAN_USE_MP11)
#include <boost/type_traits/remove_reference.hpp>
#endif
namespace test {
BOOST_PARAMETER_FUNCTION((int), h, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *, 1.f)
(index, (int), 2)
)
)
{
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
static_assert(
std::is_same<
typename std::remove_const<
typename std::remove_reference<index_type>::type
>::type
, int
>::value
, "remove_cref<index_type>::type == int"
);
#elif !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) && \
!BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
BOOST_MPL_ASSERT((
typename boost::mpl::if_<
boost::is_same<
typename boost::remove_const<
typename boost::remove_reference<index_type>::type
>::type
, int
>
, boost::mpl::true_
, boost::mpl::false_
>::type
));
#endif // BOOST_PARAMETER_CAN_USE_MP11 || Borland/MSVC workarounds not needed
tester(name, value, index);
return 1;
}
BOOST_PARAMETER_FUNCTION((int), h2, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *, 1.f)
(index, (int), static_cast<int>(value * 2))
)
)
{
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
static_assert(
std::is_same<
typename std::remove_const<
typename std::remove_reference<index_type>::type
>::type
, int
>::value
, "remove_cref<index_type>::type == int"
);
#elif !BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x564)) && \
!BOOST_WORKAROUND(BOOST_MSVC, <= 1300)
BOOST_MPL_ASSERT((
typename boost::mpl::if_<
boost::is_same<
typename boost::remove_const<
typename boost::remove_reference<index_type>::type
>::type
, int
>
, boost::mpl::true_
, boost::mpl::false_
>::type
));
#endif // BOOST_PARAMETER_CAN_USE_MP11 || Borland/MSVC workarounds not needed
tester(name, value, index);
return 1;
}
} // namespace test
#include <string>
#if !defined(BOOST_NO_SFINAE)
#include <boost/parameter/aux_/preprocessor/nullptr.hpp>
#include <boost/core/enable_if.hpp>
#if !defined(BOOST_PARAMETER_CAN_USE_MP11)
#include <boost/type_traits/is_base_of.hpp>
#include <boost/type_traits/is_convertible.hpp>
#endif
#endif
namespace test {
struct base_0
{
float f;
int i;
template <typename Args>
explicit base_0(
Args const& args
#if !defined(BOOST_NO_SFINAE)
, typename boost::disable_if<
typename boost::mpl::if_<
boost::is_base_of<base_0,Args>
, boost::mpl::true_
, boost::mpl::false_
>::type
>::type* = BOOST_PARAMETER_AUX_PP_NULLPTR
#endif // BOOST_NO_SFINAE
) : f(args[test::_value | 1.f]), i(args[test::_index | 2])
{
}
};
struct class_0 : test::base_0
{
BOOST_PARAMETER_CONSTRUCTOR(class_0, (test::base_0), test::tag,
(optional
(value, *)
(index, *)
)
)
BOOST_PARAMETER_BASIC_FUNCTION_CALL_OPERATOR((int), test::tag,
(optional
(value, *)
(index, *)
)
)
{
this->f = args[test::_value | 2.f];
this->i = args[test::_index | 1];
return 1;
}
};
struct base_1
{
template <typename Args>
explicit base_1(
Args const& args
#if !defined(BOOST_NO_SFINAE)
, typename boost::disable_if<
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
std::is_base_of<base_1,Args>
#else
typename boost::mpl::if_<
boost::is_base_of<base_1,Args>
, boost::mpl::true_
, boost::mpl::false_
>::type
#endif
>::type* = BOOST_PARAMETER_AUX_PP_NULLPTR
#endif // BOOST_NO_SFINAE
)
{
args[test::_tester](
args[test::_name]
, args[test::_value | 1.f]
, args[test::_index | 2]
);
}
};
struct class_1 : test::base_1
{
BOOST_PARAMETER_CONSTRUCTOR(class_1, (test::base_1), test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *)
(index, *)
)
)
BOOST_PARAMETER_BASIC_MEMBER_FUNCTION((int), f, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *)
(index, *)
)
)
{
args[test::_tester](
args[test::_name]
, args[test::_value | 1.f]
, args[test::_index | 2]
);
return 1;
}
BOOST_PARAMETER_BASIC_CONST_MEMBER_FUNCTION((int), f, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *)
(index, *)
)
)
{
args[test::_tester](
args[test::_name]
, args[test::_value | 1.f]
, args[test::_index | 2]
);
return 1;
}
BOOST_PARAMETER_MEMBER_FUNCTION((int), f2, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *, 1.f)
(index, *, 2)
)
)
{
tester(name, value, index);
return 1;
}
BOOST_PARAMETER_CONST_MEMBER_FUNCTION((int), f2, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *, 1.f)
(index, *, 2)
)
)
{
tester(name, value, index);
return 1;
}
BOOST_PARAMETER_MEMBER_FUNCTION((int), static f_static, test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *, 1.f)
(index, *, 2)
)
)
{
tester(name, value, index);
return 1;
}
BOOST_PARAMETER_FUNCTION_CALL_OPERATOR((int), test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *, 1.f)
(index, *, 2)
)
)
{
tester(name, value, index);
return 1;
}
BOOST_PARAMETER_CONST_FUNCTION_CALL_OPERATOR((int), test::tag,
(required
(tester, *)
(name, *)
)
(optional
(value, *, 1.f)
(index, *, 2)
)
)
{
tester(name, value, index);
return 1;
}
};
BOOST_PARAMETER_FUNCTION((int), sfinae, test::tag,
(required
(name, (std::string))
)
)
{
return 1;
}
#if !defined(BOOST_NO_SFINAE)
// On compilers that actually support SFINAE, add another overload
// that is an equally good match and can only be in the overload set
// when the others are not. This tests that the SFINAE is actually
// working. On all other compilers we're just checking that everything
// about SFINAE-enabled code will work, except of course the SFINAE.
template <typename A0>
typename boost::enable_if<
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
std::is_same<int,A0>
#else
typename boost::mpl::if_<
boost::is_same<int,A0>
, boost::mpl::true_
, boost::mpl::false_
>::type
#endif
, int
>::type
sfinae(A0 const& a0)
{
return 0;
}
#endif // BOOST_NO_SFINAE
struct predicate
{
template <typename T, typename Args>
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
using fn = std::is_convertible<T,std::string>;
#else
struct apply
: boost::mpl::if_<
boost::is_convertible<T,std::string>
, boost::mpl::true_
, boost::mpl::false_
>
{
};
#endif
BOOST_PARAMETER_BASIC_CONST_FUNCTION_CALL_OPERATOR((bool), test::tag,
(required
(value, *)
(index, *)
)
)
{
return args[test::_value] < args[test::_index];
}
};
BOOST_PARAMETER_FUNCTION((int), sfinae1, test::tag,
(required
(name, *(test::predicate))
)
)
{
return 1;
}
#if !defined(BOOST_NO_SFINAE)
// On compilers that actually support SFINAE, add another overload
// that is an equally good match and can only be in the overload set
// when the others are not. This tests that the SFINAE is actually
// working. On all other compilers we're just checking that everything
// about SFINAE-enabled code will work, except of course the SFINAE.
template <typename A0>
typename boost::enable_if<
#if defined(BOOST_PARAMETER_CAN_USE_MP11)
std::is_same<int,A0>
#else
typename boost::mpl::if_<
boost::is_same<int,A0>
, boost::mpl::true_
, boost::mpl::false_
>::type
#endif
, int
>::type
sfinae1(A0 const& a0)
{
return 0;
}
#endif // BOOST_NO_SFINAE
struct udt
{
udt(int foo_, int bar_) : foo(foo_), bar(bar_)
{
}
int foo;
int bar;
};
BOOST_PARAMETER_FUNCTION((int), lazy_defaults, test::tag,
(required
(name, *)
)
(optional
(value, *, name.foo)
(index, *, name.bar)
)
)
{
return 0;
}
} // namespace test
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
#include <boost/parameter/aux_/as_lvalue.hpp>
#endif
#include <boost/core/lightweight_test.hpp>
int main()
{
test::f(
test::values(std::string("foo"), 1.f, 2)
, std::string("foo")
);
test::f(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
int index_lvalue = 2;
test::f(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
, test::_value = 1.f
, test::_index = index_lvalue
);
test::f(
test::values(std::string("foo"), 1.f, 2)
, std::string("foo")
, 1.f
, index_lvalue
);
test::g(
test::values(std::string("foo"), 1.f, 2)
, std::string("foo")
, 1.f
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
, boost::parameter::aux::as_lvalue(2)
#else
, 2
#endif
);
test::h(
test::values(std::string("foo"), 1.f, 2)
, std::string("foo")
, 1.f
#if BOOST_WORKAROUND(BOOST_MSVC, == 1300)
, boost::parameter::aux::as_lvalue(2)
#else
, 2
#endif
);
test::h2(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
, test::_value = 1.f
);
test::class_0 u;
BOOST_TEST(2 == u.i);
BOOST_TEST(1.f == u.f);
u();
BOOST_TEST(1 == u.i);
BOOST_TEST(2.f == u.f);
test::class_1 x(
test::values(std::string("foo"), 1.f, 2)
, std::string("foo")
, test::_index = 2
);
x.f(test::values(std::string("foo"), 1.f, 2), std::string("foo"));
x.f(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
x.f2(test::values(std::string("foo"), 1.f, 2), std::string("foo"));
x.f2(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
x(test::values(std::string("foo"), 1.f, 2), std::string("foo"));
x(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
test::class_1 const& x_const = x;
x_const.f(test::values(std::string("foo"), 1.f, 2), std::string("foo"));
x_const.f(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
x_const.f2(test::values(std::string("foo"), 1.f, 2), std::string("foo"));
x_const.f2(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
test::class_1::f_static(
test::values(std::string("foo"), 1.f, 2)
, std::string("foo")
);
test::class_1::f_static(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
x_const(test::values(std::string("foo"), 1.f, 2), std::string("foo"));
x_const(
test::_tester = test::values(std::string("foo"), 1.f, 2)
, test::_name = std::string("foo")
);
test::predicate p;
test::predicate const& p_const = p;
BOOST_TEST(p_const(3, 4));
BOOST_TEST(!p_const(4, 3));
BOOST_TEST(!p_const(test::_index = 3, test::_value = 4));
#if !defined(BOOST_NO_SFINAE) && \
!BOOST_WORKAROUND(BOOST_BORLANDC, BOOST_TESTED_AT(0x592))
// GCC 3- tries to bind string literals
// to non-const references to char const*.
// BOOST_TEST(test::sfinae("foo") == 1);
char const* foo_str = "foo";
BOOST_TEST(test::sfinae(foo_str) == 1);
BOOST_TEST(test::sfinae(1) == 0);
#if !BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x580))
// Sun actually eliminates the desired overload for some reason.
// Disabling this part of the test because SFINAE abilities are
// not the point of this test.
BOOST_TEST(test::sfinae1(foo_str) == 1);
#endif
BOOST_TEST(test::sfinae1(1) == 0);
#endif
test::lazy_defaults(test::_name = test::udt(0, 1));
test::lazy_defaults(test::_name = 0, test::_value = 1, test::_index = 2);
return boost::report_errors();
}
|