70 lines
1.5 KiB
C++
70 lines
1.5 KiB
C++
//#define USE_STD_ARRAY
|
|
//#define WITH_VWR
|
|
|
|
#if defined(WITH_VWR)
|
|
# include <vectorwrapper/vectorops.hpp>
|
|
#endif
|
|
#if defined(USE_STD_ARRAY)
|
|
# include <array>
|
|
#endif
|
|
#include <cstddef>
|
|
#include <iostream>
|
|
|
|
namespace {
|
|
#if !defined(USE_STD_ARRAY)
|
|
struct MyVecStruct {
|
|
float x, y, z;
|
|
};
|
|
#endif
|
|
} //unnamed namespace
|
|
|
|
#if defined(WITH_VWR)
|
|
namespace vwr {
|
|
#if defined(USE_STD_ARRAY)
|
|
template <> struct VectorWrapperInfo<std::array<float, 3>> {
|
|
enum { dimensions = 3 };
|
|
typedef float scalar_type;
|
|
typedef std::array<float, 3> vector_type;
|
|
static scalar_type& get_at (std::size_t idx, vector_type& v) {
|
|
return v[idx];
|
|
}
|
|
};
|
|
#else
|
|
template <> struct VectorWrapperInfo<MyVecStruct> {
|
|
enum { dimensions = 3 };
|
|
typedef float scalar_type;
|
|
typedef MyVecStruct vector_type;
|
|
enum {
|
|
offset_x = offsetof(MyVecStruct, x),
|
|
offset_y = offsetof(MyVecStruct, y),
|
|
offset_z = offsetof(MyVecStruct, z)
|
|
};
|
|
};
|
|
#endif
|
|
} //namespace vwr
|
|
|
|
namespace {
|
|
#if defined(USE_STD_ARRAY)
|
|
typedef vwr::Vec<std::array<float, 3>, 3> vec3;
|
|
#else
|
|
typedef vwr::Vec<MyVecStruct, 3> vec3;
|
|
#endif
|
|
} //unnamed namespace
|
|
#endif
|
|
|
|
int main() {
|
|
#if defined(WITH_VWR)
|
|
vec3 v;
|
|
std::cin >> v.x() >> v.y() >> v.z();
|
|
const float sum = v.x() + v.y() + v.z();
|
|
#elif defined(USE_STD_ARRAY)
|
|
std::array<float, 3> arr;
|
|
std::cin >> arr[0] >> arr[1] >> arr[2];
|
|
const float sum = arr[0] + arr[1] + arr[2];
|
|
#else
|
|
MyVecStruct v;
|
|
std::cin >> v.x >> v.y >> v.z;
|
|
const float sum = v.x + v.y + v.z;
|
|
#endif
|
|
return static_cast<int>(sum);
|
|
}
|