Skip to content

Commit

Permalink
try using metaprogramming to get the right type
Browse files Browse the repository at this point in the history
  • Loading branch information
jadebenn committed Nov 22, 2024
1 parent b799f89 commit 226b36d
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
9 changes: 5 additions & 4 deletions dCommon/Amf3.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,7 @@ using AMFStringValue = AMFValue<std::string>;
using AMFDoubleValue = AMFValue<double>;

// Template deduction guide to ensure string literals deduce
template <size_t N>
AMFValue(const char (&)[N]) -> AMFValue<std::string>; // AMFStringValue
AMFValue(const char*) -> AMFValue<std::string>; // AMFStringValue

/**
* The AMFArrayValue object holds 2 types of lists:
Expand Down Expand Up @@ -297,8 +296,10 @@ class AMFArrayValue : public AMFBaseValue {
*
* @return The AMFValue
*/
template <typename AmfType>
[[nodiscard]] AMFValue<AmfType>* Get(const std::string_view key) const {
template <typename T>
[[nodiscard]] AMFValue<auto>* Get(const std::string_view key) const {

Check failure on line 300 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

a template-argument cannot be a type that contains 'auto' [D:\a\DarkflameServer\DarkflameServer\build\msvc\dGame\dGameBase.vcxproj]

Check failure on line 300 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (windows-2022)

a template-argument cannot be a type that contains 'auto' [D:\a\DarkflameServer\DarkflameServer\build\msvc\dCommon\dCommon.vcxproj]

Check failure on line 300 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

‘auto’ not permitted in template argument

Check failure on line 300 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

template argument 1 is invalid

Check failure on line 300 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (macos-13)

'auto' not allowed in template argument
using AmfType = std::invoke_result_t<AMFValue(T)>;

Check failure on line 301 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

template argument 1 is invalid

Check failure on line 301 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

‘<expression error>’ in namespace ‘std’ does not name a type

Check failure on line 301 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (macos-13)

use of class template 'AMFValue' requires template arguments; argument deduction not allowed in function return type

const AMFAssociative::const_iterator it = m_Associative.find(key);
return it != m_Associative.cend() ?

Check failure on line 304 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (macos-13)

cannot initialize return object of type 'int *' with an rvalue of type 'pointer' (aka 'AMFBaseValue *')
dynamic_cast<AMFValue<AmfType>*>(it->second.get()) :

Check failure on line 305 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

‘AmfType’ was not declared in this scope

Check failure on line 305 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

template argument 1 is invalid

Check failure on line 305 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

expected ‘>’ before ‘*’ token

Check failure on line 305 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

expected ‘(’ before ‘*’ token

Check failure on line 305 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

expected primary-expression before ‘>’ token

Check failure on line 305 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (ubuntu-22.04)

expected ‘)’ before ‘:’ token

Check failure on line 305 in dCommon/Amf3.h

View workflow job for this annotation

GitHub Actions / Build & Test (macos-13)

use of undeclared identifier 'AmfType'
Expand Down
4 changes: 2 additions & 2 deletions tests/dCommonTests/Amf3Tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ TEST(dCommonTests, AMF3InsertionAssociativeTest) {
array.Insert<std::vector<uint32_t>>("Undefined", {});
array.Insert("Null", nullptr);

ASSERT_EQ(array.Get("CString")->GetValueType(), eAmf::String);
ASSERT_EQ(array.Get<const char*>("CString")->GetValueType(), eAmf::String);
ASSERT_EQ(array.Get<std::string>("String")->GetValueType(), eAmf::String);
ASSERT_EQ(array.Get<bool>("False")->GetValueType(), eAmf::False);
ASSERT_EQ(array.Get<bool>("True")->GetValueType(), eAmf::True);
Expand All @@ -95,7 +95,7 @@ TEST(dCommonTests, AMF3InsertionDenseTest) {
array.Push<std::vector<uint32_t>>({});

ASSERT_EQ(array.Get<std::string>(0)->GetValueType(), eAmf::String);
ASSERT_EQ(array.Get(1)->GetValueType(), eAmf::String);
ASSERT_EQ(array.Get<const char*>(1)->GetValueType(), eAmf::String);
ASSERT_EQ(array.Get<bool>(2)->GetValueType(), eAmf::False);
ASSERT_EQ(array.Get<bool>(3)->GetValueType(), eAmf::True);
ASSERT_EQ(array.Get<int32_t>(4)->GetValueType(), eAmf::Integer);
Expand Down

0 comments on commit 226b36d

Please sign in to comment.