#pragma region CPL License /* Nuclex Native Framework Copyright (C) 2002-2023 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #if !defined(NUCLEX_SUPPORT_SERVICES_LAZYSERVICEINJECTOR_H) #error This header must be included via LazyServiceInjector.h #endif #include // for std::size_t #include // for std::enable_if, std::is_constructible namespace Nuclex { namespace Support { namespace Services { // ------------------------------------------------------------------------------------------- // namespace Private { /// Detects the constructor signature of the specified type /// Type whose constructor will be detected /// /// Integer sequence of length matching the argument count /// /// /// /// This uses SFINAE to pick between two implementations, one that inherits from /// the type if the argument count matches /// and one that inherits from another constructor detector with N + 1 arguments. /// /// /// So if you have a type with 2 injectable arguments, there'll be a constructor /// detector for default-constructible types, inheriting from a constructor detector /// for 1 argument, inheriting from a construftor detector for 2 arguments, finally /// inheriting from a for 2 arguments. /// /// template class ConstructorSignatureDetector; /// Detects the constructor signature of the specified type /// Type whose constructor will be detected /// /// Starting try, used if the type is default-constructible /// template class ConstructorSignatureDetector< TImplementation, IntegerSequence<>, typename std::enable_if< std::is_constructible::value >::type > : public ConstructorSignature<> {}; /// Detects the constructor signature of the specified type /// Type whose constructor will be detected /// /// Starting try, delegates to check with 1 argument if type is not default-constructible /// template class ConstructorSignatureDetector < TImplementation, IntegerSequence<>, typename std::enable_if< !std::is_constructible::value >::type > : public ConstructorSignatureDetector>::Type {}; /// Detects the constructor signature of the specified type /// Type whose constructor will be detected /// /// Intermediate successful attempt, used if the argument count matches /// template class ConstructorSignatureDetector < TImplementation, IntegerSequence, typename std::enable_if< (sizeof...(TArgumentIndices) > 0) && (sizeof...(TArgumentIndices) < MaximumConstructorArgumentCount) && std::is_constructible< TImplementation, ConstructorArgument... >::value >::type > : public ConstructorSignature...> {}; /// Detects the constructor signature of the specified type /// Type whose constructor will be detected /// /// Intermediate failed attempt, delegates recursively to check with N + 1 arguments /// template class ConstructorSignatureDetector< TImplementation, IntegerSequence, typename std::enable_if< (sizeof...(TArgumentIndices) > 0) && (sizeof...(TArgumentIndices) < MaximumConstructorArgumentCount) && !std::is_constructible< TImplementation, ConstructorArgument... >::value >::type > : public ConstructorSignatureDetector< TImplementation, BuildIntegerSequence >::Type {}; /// Detects the constructor signature of the specified type /// Type whose constructor will be detected /// /// Last attempt, used if the argument count matches the maximum number of arguments /// template class ConstructorSignatureDetector< TImplementation, IntegerSequence, typename std::enable_if< (sizeof...(TArgumentIndices) == MaximumConstructorArgumentCount) && std::is_constructible< TImplementation, ConstructorArgument... >::value >::type > : public ConstructorSignature...> {}; /// Detects the constructor signature of the specified type /// Type whose constructor will be detected /// /// Last attempt, also failed, inherits from an invalid signature marker type /// template class ConstructorSignatureDetector< TImplementation, IntegerSequence, typename std::enable_if< (sizeof...(TArgumentIndices) == MaximumConstructorArgumentCount) && !std::is_constructible< TImplementation, ConstructorArgument... >::value >::type > : public InvalidConstructorSignature {}; } // namespace Private // ------------------------------------------------------------------------------------------- // namespace Private { /// Detects the constructor signature for the specified type /// /// Type for which the constructor signature will be detectd /// template using DetectConstructorSignature = typename ConstructorSignatureDetector< TImplementation, BuildIntegerSequence<0> >::Type; } // namespace Private // ------------------------------------------------------------------------------------------- // }}} // namespace Nuclex::Support::Services