33 namespace SharedByValueSupport {
41 template <
typename T,
typename SHARED_IMPL = shared_ptr<T>>
49 template <
typename T,
typename SHARED_IMPL = shared_ptr<T>>
51#if __cplusplus >= kStrokia_Foundation_Common_cplusplus_23 || _HAS_CXX23
52 static SHARED_IMPL operator() (
const T& t);
54 SHARED_IMPL operator() (
const T& t)
const;
67 template <
typename COPIER_TYPE,
typename T,
typename SHARED_IMPL>
68 concept ICopier =
requires (COPIER_TYPE copier, SHARED_IMPL, T t) {
69 { copier (t) } -> same_as<SHARED_IMPL>;
75 template <
typename COPIER_TYPE,
typename T,
typename SHARED_IMPL>
89 template <
typename TRAITS,
typename T>
91 requires (TRAITS, T t) {
92 typename TRAITS::element_type;
93 typename TRAITS::shared_ptr_type;
98 typename TRAITS::default_copier_type;
99 { TRAITS::kDefaultCopier } -> IOptionalCopier<T, typename TRAITS::shared_ptr_type>;
104 typename TRAITS::instance_defined_copier_type;
105 {
typename TRAITS::instance_defined_copier_type{} } -> IOptionalCopier<T, typename TRAITS::shared_ptr_type>;
106 } and Common::ICVRefTd<typename TRAITS::instance_defined_copier_type>
109 requires (TRAITS, T t) {
110 typename TRAITS::element_copier_type;
111 {
typename TRAITS::element_copier_type{} } -> ICopier<T, typename TRAITS::shared_ptr_type>;
112 } and Common::ICVRefTd<typename TRAITS::element_copier_type>
114 and not(same_as<typename TRAITS::instance_defined_copier_type, MissingCopierTypeSentinel> and
119 convertible_to<decltype (TRAITS::kDefaultCopier), typename TRAITS::instance_defined_copier_type>);
130 template <typename T, typename SHARED_IMPL, IOptionalCopier<T, SHARED_IMPL> DEFAULT_COPIER_TYPE, DEFAULT_COPIER_TYPE DEFAULT_COPIER, IOptionalCopier<T, SHARED_IMPL> INSTANCE_COPIER_TYPE>
189 template <
typename T, auto COPIER_INSTANCE = &DefaultValueCopier<T, shared_ptr<T>>>
193 static_assert (ITraits<DefaultTraits_NoInstanceCopier<int, DefaultValueCopier_FunctionObject<int>{}>,
int>);
194 static_assert (ITraits<DefaultTraits_NoInstanceCopier<int>,
int>);
195 static_assert (ITraits<DefaultTraits_NoInstanceCopier<int, &DefaultValueCopier<int>>,
int>);
207 template <typename T, typename COPIER_TYPE = function<shared_ptr<T> (
const T&)>>
210 static_assert (ITraits<DefaultTraits_InstanceCopierOnly<int>,
int>);
221 template <
typename T,
typename DEFAULT_COPIER_TYPE = DefaultValueCopier_FunctionObject<T, shared_ptr<T>>,
222 typename INSTANCE_COPIER_TYPE = function<shared_ptr<T> (const T&)>>
225 static_assert (ITraits<DefaultTraits_DefaultAndInstanceCopiers<int>,
int>);
242 template <
typename T, auto COPIER_INSTANCE = &DefaultValueCopier<T, shared_ptr<T>>>
322 using TraitsType = TRAITS;
325 using element_type =
typename TRAITS::element_type;
326 using element_copier_type =
typename TRAITS::element_copier_type;
327 using shared_ptr_type =
typename TRAITS::shared_ptr_type;
329 using instance_defined_copier_type =
typename TRAITS::instance_defined_copier_type;
330 using default_copier_type =
typename TRAITS::default_copier_type;
333 static_assert (same_as<T, typename TRAITS::element_type>);
353#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
355 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>)
358 if constexpr (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>) {
359 fCopier_ = TRAITS::kDefaultCopier;
363 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>)
366 if constexpr (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>) {
367 fCopier_ = TRAITS::kDefaultCopier;
372 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>);
374 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>);
378#if qCompilerAndStdLib_RequiresNotMatchInlineOutOfLineForTemplateClassBeingDefined_Buggy
380 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>)
383 if constexpr (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>) {
384 fCopier_ = TRAITS::kDefaultCopier;
388 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>)
389 : fSharedImpl_{TRAITS::kDefaultCopier (from)}
391 if constexpr (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>) {
392 fCopier_ = TRAITS::kDefaultCopier;
396 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>)
397 : fSharedImpl_{move (from)}
399 if constexpr (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>) {
400 fCopier_ = TRAITS::kDefaultCopier;
403 SharedByValue (
const shared_ptr_type& from,
const instance_defined_copier_type& copier)
noexcept
404 requires (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>)
409 SharedByValue (
const element_type& from,
const instance_defined_copier_type& copier)
410 requires (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>)
412 , fSharedImpl_{copier (from)}
415 SharedByValue (shared_ptr_type&& from,
const instance_defined_copier_type&& copier)
noexcept
416 requires (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>)
417 : fCopier_{move (copier)}
418 , fSharedImpl_{move (from)}
423 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>);
424 explicit SharedByValue (
const shared_ptr_type& from)
noexcept
425 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>);
427 requires (not same_as<default_copier_type, MissingCopierTypeSentinel>);
428 SharedByValue (
const element_type& from,
const instance_defined_copier_type& copier)
429 requires (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>);
430 SharedByValue (
const shared_ptr_type& from,
const instance_defined_copier_type& copier)
noexcept
431 requires (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>);
432 SharedByValue (shared_ptr_type&& from,
const instance_defined_copier_type&& copier)
noexcept
433 requires (not same_as<instance_defined_copier_type, MissingCopierTypeSentinel>);
439 nonvirtual
SharedByValue& operator= (shared_ptr_type&& from)
noexcept;
440 nonvirtual
SharedByValue& operator= (
const shared_ptr_type& from)
noexcept;
448 nonvirtual
explicit operator bool ()
const noexcept;
457 nonvirtual shared_ptr_type
cget_ptr ()
const;
466 template <
typename COPIER>
467 nonvirtual shared_ptr_type
rwget_ptr (COPIER&& copier);
479 nonvirtual element_type*
rwget ();
480 template <
typename COPIER>
481 nonvirtual element_type*
rwget (COPIER&& copier);
491 nonvirtual
const element_type*
cget ()
const noexcept;
504 nonvirtual
const element_type*
operator->()
const;
511 nonvirtual
const element_type&
operator* ()
const;
516 constexpr bool operator== (nullptr_t)
const;
521 nonvirtual element_copier_type GetElementCopier ()
const;
537 nonvirtual
bool unique ()
const;
545 nonvirtual
unsigned int use_count ()
const;
548 using DeclaredInstanceCopierType_ =
549 conditional_t<same_as<instance_defined_copier_type, MissingCopierTypeSentinel>,
Common::Empty, instance_defined_copier_type>;
550 shared_ptr_type fSharedImpl_;
562 template <
typename COPIER>
567 template <
typename COPIER>
568 nonvirtual
void BreakReferences_ (COPIER&& copier);