Better is_default_constructible in C++98

Đang mở
#201 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tái cấu trúc
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
cpp
Lĩnh vực
compilers

Hướng nghiên cứu

Bắt đầu trong boost/type_traits/is_default_constructible.hpp, đặc biệt là các dòng 84–92 và phần triển khai trait xung quanh. So sánh helper C++98 được đề xuất với hành vi hiện tại, sau đó xác nhận rằng trait xử lý các trường hợp void, mảng và tham chiếu được liệt kê trong khi vẫn tương thích với C++98.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

  • Lines 84 to 92 in boost/type_traits/is_default_constructible.hpp are the compromise solution without std::decltype. In fact, there are better solutions.

  • The original code is as follows(line 84 ~ 92 in boost/type_traits/is_default_constructible.hpp)
   // We don't know how to implement this, note we can not use has_trivial_constructor here
   // because the correct implementation of that trait requires this one:
   template <class T> struct is_default_constructible : public is_pod<T>{};
   template <> struct is_default_constructible<void> : public integral_constant<bool, false>{};
   template <> struct is_default_constructible<void const> : public integral_constant<bool, false>{};
   template <> struct is_default_constructible<void volatile> : public integral_constant<bool, false>{};
   template <> struct is_default_constructible<void const volatile> : public integral_constant<bool, false>{};
  • Better solution (without std::decltype or other C++11 feature)
  // __is_default_constructible_helper
  template <typename T, bool not_void>
  struct __is_default_constructible_helper
  {
    typedef char        yes[1];
    typedef char        no[2];

    template <typename U>
    static yes& check(int (*) [sizeof((U()))]);

    template <typename U>
    static no& check(...);

    static const bool value = sizeof(check<T>(0)) == sizeof(yes);
  };

  // void : false
  template <typename T>
  struct __is_default_constructible_helper<T, false>
  : public false_type { };

  // T[S] -> T
  template <typename T, size_t S>
  struct __is_default_constructible_helper<T[S], true>
  : public __is_default_constructible_helper<T, true> { };

  // T[] : false
  template <typename T>
  struct __is_default_constructible_helper<T[], true>
  : public false_type { };

  // T&& and T& : false
  template <typename T>
  struct __is_default_constructible_helper<T&, true>
  : public false_type { };

#if __cplusplus >= 201103L
  template <typename T>
  struct __is_default_constructible_helper<T&&, true>
  : public false_type { };
#endif // __cplusplus >= 201103L

  /// is_default_constructible
  template <typename T>
  struct is_default_constructible
  : public kim::bool_constant<
    __is_default_constructible_helper<
      typename kim::__remove_cv<T>::type, !is_void<T>::value
    >::value
  >::type
  { };
Ngôn ngữ chính
C++
Star
65
Fork
88
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của boostorg/type_traits

Tất cả issue của boostorg/type_traits

Issue tương tự

Thêm issue về C++

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.