-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix has_static_new #1013
Fix has_static_new #1013
Changes from 4 commits
65da840
5893611
2032a6c
e0a5b7f
fcf91a6
d352155
c3b1768
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -45,3 +45,5 @@ autowiring.kdev4 | |
autowiring.VC.db | ||
.vscode | ||
AutowiringVersion.h | ||
|
||
*.VC.db* | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,51 +5,18 @@ | |
|
||
namespace autowiring { | ||
|
||
/// <summary> | ||
/// Utility helper structure for types which have a factory New routine | ||
/// </summary> | ||
/// <remarks> | ||
/// A factory New routine is malformed when the return type is not implicitly castable to type T | ||
/// </remarks> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should keep the comments? I found the |
||
template<class T, class Selector, class... Args> | ||
struct has_well_formed_static_new { | ||
static const bool value = std::is_convertible< | ||
decltype( | ||
T::New( | ||
std::declval<Args>()... | ||
) | ||
), | ||
T* | ||
>::value; | ||
}; | ||
|
||
template<class T, class... Args> | ||
struct has_well_formed_static_new<T, std::false_type, Args...> { | ||
static const bool value = false; | ||
}; | ||
|
||
template<typename T, typename... Args> | ||
struct has_static_new | ||
template <class T, typename... Args> | ||
class has_static_new | ||
{ | ||
template<class U> | ||
static std::true_type select(decltype(U::New((Args&&)*(Args*)nullptr...))*); | ||
|
||
template<class U> | ||
static std::false_type select(...); | ||
|
||
static const bool value = has_well_formed_static_new<T, decltype(select<T>(nullptr)), Args...>::value; | ||
}; | ||
|
||
template<typename T> | ||
struct has_static_new<T> | ||
{ | ||
template<class U> | ||
static std::true_type select(decltype(U::New())*); | ||
|
||
template<class U> | ||
static std::false_type select(...); | ||
|
||
static const bool value = has_well_formed_static_new<T, decltype(select<T>(nullptr))>::value; | ||
template<class U, class = typename std::enable_if< | ||
std::is_function<decltype(U::New(std::declval<Args>()...))(Args...)>::value && | ||
std::is_convertible<decltype(U::New(std::declval<Args>()...)), T*>::value | ||
>::type> | ||
static std::true_type check(void*); | ||
template <class...> | ||
static std::false_type check(...); | ||
public: | ||
static const bool value = decltype(check<T>(nullptr))::value; | ||
}; | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,11 @@ namespace { | |
}; | ||
} | ||
|
||
static_assert( | ||
autowiring::select_strategy<HasDefaultCtorAndOthers, int>::value == autowiring::construction_strategy::standard, | ||
"Construction strategy incorrectly inferred" | ||
); | ||
|
||
TEST_F(AutoConstructTest, AutoConstructNoArgs) { | ||
AutoConstruct<HasDefaultCtorAndOthers> hdcao; | ||
ASSERT_EQ(101, hdcao->v) << "Default constructor was not called as expected"; | ||
|
@@ -102,3 +107,65 @@ TEST_F(AutoConstructTest, FactoryNewPrivateCtor) { | |
ASSERT_NE(nullptr, mpcc.get()) << "Null not expected as a return type from a factory new construction"; | ||
ASSERT_EQ(1002, mpcc->ival) << "Correct ctor was not invoked on a type with a private ctor"; | ||
} | ||
|
||
namespace { | ||
class MyPrivateCtorStringClass : | ||
public CoreObject | ||
{ | ||
MyPrivateCtorStringClass(void) : | ||
istr("default_string") | ||
{} | ||
MyPrivateCtorStringClass(const char* istr) : | ||
istr(istr) | ||
{} | ||
|
||
public: | ||
const char* istr; | ||
|
||
static MyPrivateCtorStringClass* New(const char* str) { | ||
return new MyPrivateCtorStringClass{ str }; | ||
} | ||
}; | ||
} | ||
|
||
static_assert( | ||
autowiring::has_static_new<MyPrivateCtorStringClass, decltype("")>::value, | ||
"Failed to find factory new on a type that carries it" | ||
); | ||
static_assert( | ||
autowiring::select_strategy<MyPrivateCtorStringClass, decltype("")>::value == autowiring::construction_strategy::factory_new, | ||
"Construction strategy incorrectly inferred" | ||
); | ||
static_assert( | ||
!std::is_constructible<MyPrivateCtorStringClass>::value, | ||
"Type reported as being constructable when it was not" | ||
); | ||
static_assert( | ||
!autowiring::has_simple_constructor<MyPrivateCtorStringClass>::value, | ||
"Simple constructor detected when said constructor should have been private" | ||
); | ||
|
||
TEST_F(AutoConstructTest, FactoryNewPrivateStringCtor) { | ||
AutoConstruct<MyPrivateCtorStringClass> mpcc{ "a new string" }; | ||
ASSERT_NE(nullptr, mpcc.get()) << "Null not expected as a return type from a factory new construction"; | ||
ASSERT_STREQ("a new string", mpcc->istr) << "Correct ctor was not invoked on a type with a private ctor"; | ||
} | ||
|
||
class MultiStaticNew : public CoreObject { | ||
MultiStaticNew() {} | ||
public: | ||
static char* New() { return nullptr; } | ||
static MultiStaticNew* New(int x) { return nullptr; } | ||
}; | ||
static_assert( | ||
!autowiring::has_static_new<MultiStaticNew>::value, | ||
"Found a bad static new" | ||
); | ||
static_assert( | ||
autowiring::has_static_new<MultiStaticNew, int>::value, | ||
"Failed to find a good static new override" | ||
); | ||
|
||
TEST_F(AutoConstructTest, MultiStaticNewTest) { | ||
AutoConstruct<MultiStaticNew> badstatic{ 1 }; | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing newline at EOF There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This var is named |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
`Autowiring.VC.db is already listed above though?
Or if the intent here is the trailing asterisk, are there circumstances when it makes a db1, db2 file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, 2017 adds several extensions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see now. I have
Browse.VC.db
andSolution.VC.db{,-shm,-wal}
.Should remove the now-redundant
autowiring.VC.db
above then?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yep