Skip to content

Commit

Permalink
Hack to fix C++17 build.
Browse files Browse the repository at this point in the history
  • Loading branch information
sean-parent committed Nov 8, 2024
1 parent 2e8b826 commit 0f69ed8
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 15 deletions.
25 changes: 25 additions & 0 deletions CMakePresets.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,31 @@
}
}
},
{
"name": "debug-windows-cpp17",
"displayName": "debug-windows-cpp17",
"description": "Sets Ninja generator, build and install directory",
"generator": "Ninja",
"binaryDir": "${sourceDir}/build/${presetName}",
"cacheVariables": {
"CMAKE_BUILD_TYPE": "Debug",
"CMAKE_CXX_STANDARD": "17",
"CMAKE_INSTALL_PREFIX": "${sourceDir}/out/install/${presetName}",
"VCPKG_TARGET_TRIPLET": "x64-windows"
},
"architecture": {
"value": "x64",
"strategy": "external"
},
"toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
"vendor": {
"microsoft.com/VisualStudioSettings/CMake/1.0": {
"hostOS": [
"Windows"
]
}
}
},
{
"name": "macos-debug-C++20",
"displayName": "macos-debug-C++20",
Expand Down
7 changes: 5 additions & 2 deletions adobe/iomanip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

#include <adobe/config.hpp>

#include <adobe/iomanip_fwd.hpp>

#include <cassert>
#include <functional>
#include <iosfwd>
Expand All @@ -24,12 +26,13 @@
#include <stdexcept>
#include <string>

#include <adobe/iomanip_fwd.hpp>
#include <boost/next_prior.hpp>

#include <adobe/manip.hpp>
#include <adobe/name.hpp>
#include <adobe/serializable.hpp>

#include <boost/next_prior.hpp>


/**************************************************************************************************/

Expand Down
8 changes: 7 additions & 1 deletion adobe/manip.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,17 @@

#include <iostream>

/*
REVISIT (sean-parent): As far as I can determine, this file does not use adobe/serializable.hpp
However, if it is not included here, the build fails for C++17 under MSVC only. I have not been
able to determine why this is the case.
*/
#include <adobe/serializable.hpp>

/**************************************************************************************************/

namespace adobe {


/**************************************************************************************************/

/*!
Expand Down
24 changes: 14 additions & 10 deletions adobe/serializable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@
#include <ostream>
#include <type_traits>

#include <adobe/typeinfo.hpp>
#include <adobe/string/to_string.hpp>
#include <adobe/typeinfo.hpp>


/**************************************************************************************************/

Expand Down Expand Up @@ -65,10 +66,10 @@ template <class T>
inline typename std::enable_if<!has_ostream_insertion<T>::value>::type
ostream_insertion(std::ostream&, const T&) {}

#else // __cplusplus < 202002L
#else // __cplusplus < 202002L

template <class T>
void ostream_insertion(std::ostream& s, const T& x) {
inline void ostream_insertion(std::ostream& s, const T& x) {
if constexpr (requires { s << x; }) {
s << x;
}
Expand Down Expand Up @@ -112,7 +113,7 @@ class serializable_t {

serializable_t(serializable_t&& x) : instance_m(x.instance_m.release()) {}

void operator()(std::ostream& s) const { object()(s); }
void operator()(std::ostream& s) const { object()._out(s); }

const std::type_info& type_info() const { return object().type_info(); }

Expand All @@ -123,7 +124,7 @@ class serializable_t {
if (type != typeid(T))
throw bad_cast(type, typeid(T));

return static_cast<const T&>(reinterpret_cast<const instance<T>&>(object()).object_m);
return static_cast<const instance<T>&>(object()).object_m;
}

template <typename T>
Expand All @@ -137,19 +138,22 @@ class serializable_t {

virtual instance_t* _copy() const = 0;

virtual void operator()(std::ostream& s) const = 0;
virtual void _out(std::ostream& s) const = 0;
virtual const std::type_info& type_info() const = 0;
};

template <typename T>
struct instance : instance_t {
struct instance final : instance_t {
explicit instance(T x) : object_m(std::move(x)) {}

instance_t* _copy() const { return new instance(object_m); }
instance_t* _copy() const override { return new instance(object_m); }

void operator()(std::ostream& s) const { serialize<T>()(s, object_m); }
void _out(std::ostream& s) const override {
// ostream_insertion(s, object_m);
s << object_m;
}

const std::type_info& type_info() const { return typeid(T); }
const std::type_info& type_info() const override { return typeid(T); }

T object_m;
};
Expand Down
4 changes: 2 additions & 2 deletions test/property_model_eval/iomanip_flat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
or a copy at http://stlab.adobe.com/licenses.html)
*/

// REVISIT (mmarcus) : repalce this file with merge into iomanip_asl_cel
// REVISIT (mmarcus) : replace this file with merge into iomanip_asl_cel

/**************************************************************************************************/

Expand Down Expand Up @@ -151,7 +151,7 @@ void flat_format::handle_atom(stream_type& os, bool is_push) {
} else if (value.type_info() == typeid(dictionary_t)) {
os << value.cast<dictionary_t>();
} else if (value.type_info() == typeid(array_t)) {
os << value.cast<array_t>();
os << top.value().cast<::adobe::array_t>();
} else {
os << "'cel_unknown: " << value.type_info().name() << "'";
}
Expand Down

0 comments on commit 0f69ed8

Please sign in to comment.