상태가 숫자 (using state_t = unsigned
)이고 번호가 (using transition_t = unsigned
) 인 자동 데이터를 나타내는 클래스가 있다고 해봅시다. 물론 어떤 점에서는 transition_t
과 state_t
이 같은 유형이기 때문에 컴파일러가 (의미 론적) 유형 안전을 시행하지 않기 때문에 일부 호출이 엉망이됩니다. 태그 (struct transition_tag {}; struct state_tag {};
)로 템플릿 화 된 작은 클래스를 사용하여 쉽게 해결할 수 있으므로 이제 transition_t
과 state_t
은 호환되지 않습니다. (최단 경로) 전신 전이로의 이행에서컴파일러가 적용한 의미 유형
predecessors_t
지도 :/// Lightweight state/transition handle (or index). template <typename Tag> struct index_t_impl { using index_t = unsigned; constexpr index_t_impl(index_t i) : s{i} {} // Disallow index1_t i{index2_t{42}}; template <typename T> index_t_impl(index_t_impl<T> t) = delete; bool operator==(index_t_impl t) const { return s == t.s; } // Disallow index1_t{42} == index2_t{42}; template <typename T> bool operator==(index_t_impl<T> t) const = delete; /// Default ctor to please containers. index_t_impl() = default; constexpr operator index_t() const { return s; } /// Be compliant with Boost integer ranges. index_t_impl& operator++() { ++s; return *this; } /// Be compliant with Boost integer ranges. index_t_impl& operator--() { --s; return *this; } private: index_t s; };
는 또한, 난 아주 많이 비슷 두 구조를 가지고있다. 효율성을 위해
std::vector<transition_t>
입니다.path_t
은 전환 색인 목록입니다. 효율성을 위해std::vector<transition_t>
입니다.
두 번째 완전히 다른 목적으로 std::vector<transition_t>
을 사용하는이 문제가 있습니다. 물론, 태그로 템플릿 화 된 래퍼를 다시 소개 할 수는 있지만, 다시는 더러워집니다. 공개 상속은 매우 유혹적입니다 (Thou shalt not inherit from std::vector)!
하지만 실제로 기본 유형과 완전히 다르지만 호환되지 않는 새로운 유형을 도입 할 때마다 애드혹 솔루션에 지쳐 있습니다. 이와 관련하여 권고 사항이 있습니까? 공개 상속은 정말 매력적이지만 추가 인스턴스에 톤이 부풀어 오르는 코드를 도입하지 않을까요? 아마도 Crashworks (https://stackoverflow.com/a/4353276/1353549)에서 권장하는 공개 구성 (struct predecessors_t { std::vector<transition_t> v; };
)이 더 나은 확장 옵션일까요?
미래에 C++의 새로운 점이 있습니까?
나는 그것이 표준에 들어오는 모르는 그러나 당신은 여기에서 볼 수 있습니다 : HTTP : // 유래.co.kr/questions/28916627/strong-typedefs – Hayt