result_of.pass.cpp revision 71e699dda5442545e3335f8c07de27c860fe2046
1e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com//===----------------------------------------------------------------------===// 2e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com// 3e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com// The LLVM Compiler Infrastructure 4e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com// 5e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com// This file is dual licensed under the MIT and the University of Illinois Open 6e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com// Source Licenses. See LICENSE.TXT for details. 7e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com// 8e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com//===----------------------------------------------------------------------===// 9e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com 10b3c9d1c33caf325aada244204215eb790c228c12dandov// <functional> 11e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com 12b7425173f96e93b090787e2386ba5f022b6c2869fmalita// result_of<Fn(ArgTypes...)> 13b7425173f96e93b090787e2386ba5f022b6c2869fmalita 14837f5321a409228a27fc710eb71c87866b820cfbsenorblanco#include <type_traits> 15837f5321a409228a27fc710eb71c87866b820cfbsenorblanco#include <memory> 16837f5321a409228a27fc710eb71c87866b820cfbsenorblanco 17837f5321a409228a27fc710eb71c87866b820cfbsenorblancotypedef bool (&PF1)(); 185f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.orgtypedef short (*PF2)(long); 195f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org 205f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.orgstruct S 215f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org{ 225f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org operator PF2() const; 235f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org double operator()(char, int&); 245f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org void calc(long) const; 255f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org char data_; 265f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org}; 275f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.org 285f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.orgtypedef void (S::*PMS)(long) const; 295f8c8f448673c65c5434cf1e419319eccf34117bjunov@chromium.orgtypedef char S::*PMD; 307ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com 31e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.comstruct wat 327ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com{ 33e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com wat& operator*() { return *this; } 34e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com void foo(); 35e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com}; 36ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 37ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgstruct F {}; 38ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org 39ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgtemplate <class T, class U> 40ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.orgvoid test_result_of_imp() 41ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org{ 42ed9806f5c972513d4141c9d1b5a04ab78b3af4cbcommit-bot@chromium.org static_assert((std::is_same<typename std::result_of<T>::type, U>::value), ""); 437ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com#if _LIBCPP_STD_VER > 11 440c8ec2f658a206cbedd0d955167654fae85ad5fbjunov@chromium.org static_assert((std::is_same<std::result_of_t<T>, U>::value), ""); 450c8ec2f658a206cbedd0d955167654fae85ad5fbjunov@chromium.org#endif 460c8ec2f658a206cbedd0d955167654fae85ad5fbjunov@chromium.org} 470c8ec2f658a206cbedd0d955167654fae85ad5fbjunov@chromium.org 480c8ec2f658a206cbedd0d955167654fae85ad5fbjunov@chromium.orgint main() 494469938e92d779dff05e745559e67907bbf21e78reed@google.com{ 507ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com test_result_of_imp<S(int), short> (); 510c8ec2f658a206cbedd0d955167654fae85ad5fbjunov@chromium.org test_result_of_imp<S&(unsigned char, int&), double> (); 520c8ec2f658a206cbedd0d955167654fae85ad5fbjunov@chromium.org test_result_of_imp<PF1(), bool> (); 537ce564cccb246ec56427085872b2e1458fe74bd1bsalomon@google.com test_result_of_imp<PMS(std::unique_ptr<S>, int), void> (); 54e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com test_result_of_imp<PMS(S, int), void> (); 55e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com test_result_of_imp<PMS(const S&, int), void> (); 56e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 57e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com test_result_of_imp<PMD(S), char&&> (); 58e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com#endif 59e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com test_result_of_imp<PMD(const S*), const char&> (); 606fcd28ba1de83b72f4c8343ccec27d26c127de32reed@google.com#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 61b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org test_result_of_imp<int (F::* (F &)) () &, int> (); 62b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org test_result_of_imp<int (F::* (F &)) () const &, int> (); 63b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org test_result_of_imp<int (F::* (F const &)) () const &, int> (); 64b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org test_result_of_imp<int (F::* (F &&)) () &&, int> (); 65b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org test_result_of_imp<int (F::* (F &&)) () const&&, int> (); 66b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org test_result_of_imp<int (F::* (F const&&)) () const&&, int> (); 67b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org#endif 68b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 69b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org using type1 = std::result_of<decltype(&wat::foo)(wat)>::type; 704b413c8bb123e42ca4b9c7bfa6bc2167283cb84ccommit-bot@chromium.org#endif 71b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org#if _LIBCPP_STD_VER > 11 72b3470c8c421ee8f367673a67c3408507cee04434junov@chromium.org using type2 = std::result_of_t<decltype(&wat::foo)(wat)>; 73e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com#endif 74e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com 75e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com 7604ba448579b976369075c675d847ef0f779d40f4skia.committer@gmail.com 77e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<S(int)>::type, short>::value), "Error!"); 78e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<S&(unsigned char, int&)>::type, double>::value), "Error!"); 79e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<PF1()>::type, bool>::value), "Error!"); 80e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<PMS(std::unique_ptr<S>, int)>::type, void>::value), "Error!"); 81e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<PMS(S, int)>::type, void>::value), "Error!"); 82e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<PMS(const S&, int)>::type, void>::value), "Error!"); 83e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 84e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<PMD(S)>::type, char&&>::value), "Error!"); 85e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com#endif 86e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<PMD(const S*)>::type, const char&>::value), "Error!"); 87e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com#ifndef _LIBCPP_HAS_NO_RVALUE_REFERENCES 88e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<int (F::* (F &)) () &>::type, int>::value), "Error!"); 89ec0aa764ebe36aecdfb77286d665fccc85ab204ageorge@mozilla.com static_assert((std::is_same<std::result_of<int (F::* (F &)) () const &>::type, int>::value), "Error!"); 90e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<int (F::* (F const &)) () const &>::type, int>::value), "Error!"); 91e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<int (F::* (F &&)) () &&>::type, int>::value), "Error!"); 92e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<int (F::* (F &&)) () const&&>::type, int>::value), "Error!"); 93e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com static_assert((std::is_same<std::result_of<int (F::* (F const&&)) () const&&>::type, int>::value), "Error!"); 94e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#endif 95e0d9ce890e67d02727ac2811bb456ddb64f827d4reed@google.com#ifndef _LIBCPP_HAS_NO_TEMPLATE_ALIASES 96e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com using type = std::result_of<decltype(&wat::foo)(wat)>::type; 97e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com#endif 98e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com} 99e0201a4448f5e770cc081ca3425bed528af27f8drileya@google.com