Cannot pass std::vector<bool> to winrt::array_view - c++

I trying to consume Windows::Gaming::Input::RawGameController via C++/WinRT library.
Calling RawGameController::GetCurrentReading() to acquire current controller state:
std::vector<bool> buttonsArray(rawController.ButtonCount(), false);
std::vector<GameControllerSwitchPosition> switchesArray(rawController.SwitchCount(), GameControllerSwitchPosition::Center);
std::vector<double> axisArray(rawController.AxisCount(), 0.0);
uint64_t timestamp = rawController.GetCurrentReading(buttonsArray, switchesArray, axisArray);
And have compile error:
1>------ Build started: Project: cppwinrtgamepad, Configuration: Debug x64 ------
1>cppwinrtgamepad.cpp
1>c:\somepath\x64\debug\generated files\winrt\base.h(3458): error C2039: 'data': is not a member of 'std::vector<T,std::allocator<_Ty>>'
1> with
1> [
1> T=bool,
1> _Ty=bool
1> ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(3663): note: see declaration of 'std::vector<T,std::allocator<_Ty>>'
1> with
1> [
1> T=bool,
1> _Ty=bool
1> ]
1>c:\somepath\cppwinrtgamepad.cpp(121): note: see reference to function template instantiation 'winrt::array_view<T>::array_view<T>(std::vector<T,std::allocator<_Ty>> &) noexcept' being compiled
1> with
1> [
1> T=bool,
1> _Ty=bool
1> ]
1>c:\somepath\cppwinrtgamepad.cpp(121): note: see reference to function template instantiation 'winrt::array_view<T>::array_view<T>(std::vector<T,std::allocator<_Ty>> &) noexcept' being compiled
1> with
1> [
1> T=bool,
1> _Ty=bool
1> ]
1>c:\somepath\cppwinrtgamepad.cpp(90): note: see reference to class template instantiation 'winrt::impl::fast_iterator<winrt::Windows::Foundation::Collections::IVectorView<winrt::Windows::Gaming::Input::Gamepad>>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(7801): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IContextCallback>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(7573): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IServerSecurity>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(7532): note: see reference to class template instantiation 'std::chrono::time_point<winrt::clock,winrt::Windows::Foundation::TimeSpan>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(5264): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IMarshal>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(2503): note: see reference to class template instantiation 'winrt::com_ptr<To>' being compiled
1> with
1> [
1> To=winrt::impl::ILanguageExceptionErrorInfo2
1> ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(4120): note: see reference to function template instantiation 'winrt::com_ptr<To> winrt::com_ptr<winrt::impl::IRestrictedErrorInfo>::try_as<winrt::impl::ILanguageExceptionErrorInfo2>(void) noexcept const' being compiled
1> with
1> [
1> To=winrt::impl::ILanguageExceptionErrorInfo2
1> ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(4202): note: see reference to class template instantiation 'winrt::com_ptr<winrt::impl::IRestrictedErrorInfo>' being compiled
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\string_view(39): note: see reference to class template instantiation 'std::basic_string_view<wchar_t,std::char_traits<wchar_t>>' being compiled
1>c:\somepath\x64\debug\generated files\winrt\base.h(3458): error C2664: 'winrt::array_view<T>::array_view(winrt::array_view<T> &&)': cannot convert argument 1 from 'winrt::array_view<T>::size_type' to 'std::initializer_list<bool>'
1> with
1> [
1> T=bool
1> ]
1>c:\somepath\x64\debug\generated files\winrt\base.h(3459): note: No constructor could take the source type, or constructor overload resolution was ambiguous
1>Done building project "cppwinrtgamepad.vcxproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
GetCurrentReading() is defined in winrt/Windows.Gaming.Input.h like this:
template <typename D> uint64_t consume_Windows_Gaming_Input_IRawGameController<D>::GetCurrentReading(array_view<bool> buttonArray, array_view<Windows::Gaming::Input::GameControllerSwitchPosition> switchArray, array_view<double> axisArray) const
And corresponding winrt::array_view constructor is defined in winrt/base.h like this:
template <typename C>
array_view(std::vector<C>& value) noexcept :
array_view(value.data(), static_cast<size_type>(value.size()))
{}
Looks like oblivious bug considering that std::vector<bool> doesn't contrain data() method at all.
Or there is other recommended way to call RawGameController::GetCurrentReading()?
PS: as a workaround I could use std::array<bool, SOME_BIG_BUTTTON_COUNT> but its so ugly.

This is by design. The winrt::array_view is an adapter that tells the underlying API that the bound array or storage has the appropriate binary layout to receive the data efficiently (typically via a memcpy) without some kind of transformation. std::vector<bool> does not provide that guarantee and thus cannot be used. You might want to try something else like a std::array or some other contiguous container.

Ugly workaround instead of using vector<bool>:
int32_t buttons = rawController.ButtonCount();
int32_t switches = rawController.SwitchCount();
int32_t axis = rawController.AxisCount();
std::unique_ptr<bool[]> buttonsArray = std::make_unique<bool[]>(buttons);
std::vector<GameControllerSwitchPosition> switchesArray(switches);
std::vector<double> axisArray(axis);
uint64_t timestamp = rawController.GetCurrentReading(winrt::array_view<bool>(buttonsArray.get(), buttonsArray.get() + buttons), switchesArray, axisArray);

Each element in std::vector<bool> occupies a single bit instead of sizeof(bool) bytes.It does not necessarily store its elements as a contiguous array and thus doesn't contain data() method.I have a working code, but it is not the optimal solution.You can try to create bool array by using bool b[] method.
bool buttonsArray[]{ rawController.ButtonCount(), false };
std::vector<GameControllerSwitchPosition> switchesArray(rawController.SwitchCount(), GameControllerSwitchPosition::Center);
std::vector<double> axisArray(rawController.AxisCount(), 0.0);
uint64_t timestamp = rawController.GetCurrentReading(buttonsArray, switchesArray, axisArray);

Related

boost 1.73 messages reporting during project build

I'm using Boost 1.73 on a older project which was using Boost 1.48. My intention is to fix any warnings and errors along the way.
When compiling the project I'm getting some odd messages which are not in the source of the project but in boost itself, these messages are like most error messages, cryptic and not terribly helpful.
1>debugengine.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\utility(173): warning C4244: 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data
1> with
1> [
1> _Ty=int
1> ]
1> and
1> [
1> _Ty2=unsigned short
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(111): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(99): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(168): note: see reference to function template instantiation 'unsigned short boost::date_time::month_str_to_ushort<month_type>(const std::string &)' being compiled
1>c:\boost\boost_1_73_0\boost\date_time\gregorian\parsers.hpp(49): note: see reference to function template instantiation 'date_type boost::date_time::parse_date<boost::gregorian::date>(const std::string &,int)' being compiled
1> with
1> [
1> date_type=boost::gregorian::date
1> ]
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(54): note: see reference to class template instantiation 'boost::arg<9>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(53): note: see reference to class template instantiation 'boost::arg<8>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(52): note: see reference to class template instantiation 'boost::arg<7>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(51): note: see reference to class template instantiation 'boost::arg<6>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(50): note: see reference to class template instantiation 'boost::arg<5>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(49): note: see reference to class template instantiation 'boost::arg<4>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(48): note: see reference to class template instantiation 'boost::arg<3>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(47): note: see reference to class template instantiation 'boost::arg<2>' being compiled
1>c:\boost\boost_1_73_0\boost\bind\placeholders.hpp(46): note: see reference to class template instantiation 'boost::arg<1>' being compiled
Is there anything I can do?
I'm using MSVC 2017.
I've narrowed the problem down to just one file and commented out everything except:
#include <boost/date_time.hpp>
This is what I get when compiling just this:
1>------ Build started: Project: Debug Service Group, Configuration: Debug Win32 ------
1>debugengine.cpp
1>c:\program files (x86)\microsoft visual studio\2017\professional\vc\tools\msvc\14.16.27023\include\utility(173): warning C4244: 'initializing': conversion from '_Ty' to '_Ty2', possible loss of data
1> with
1> [
1> _Ty=int
1> ]
1> and
1> [
1> _Ty2=unsigned short
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(111): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(99): note: see reference to function template instantiation 'std::pair<const _Kty,_Ty>::pair<const char(&)[4],int,0>(_Other1,_Other2 &&) noexcept(false)' being compiled
1> with
1> [
1> _Kty=std::string,
1> _Ty=unsigned short,
1> _Other1=const char (&)[4],
1> _Other2=int
1> ]
1>c:\boost\boost_1_73_0\boost\date_time\date_parsing.hpp(168): note: see reference to function template instantiation 'unsigned short boost::date_time::month_str_to_ushort<month_type>(const std::string &)' being compiled
1>c:\boost\boost_1_73_0\boost\date_time\gregorian\parsers.hpp(49): note: see reference to function template instantiation 'date_type boost::date_time::parse_date<boost::gregorian::date>(const std::string &,int)' being compiled
1> with
1> [
1> date_type=boost::gregorian::date
1> ]
1>Done building project "Debug Service Group.vcxproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========
The warnings are harmless. Here's the source in boost\date_time\date_parsing.hpp line 99
static std::map<std::string, unsigned short> month_map =
{ { "jan", 1 }, { "january", 1 },
As you can see the value type of the map is unsigned short but it is being initialised with int values.
I'm slightly surprised at the warning, you might think that MSVC 2017 would be smart enough to realise that assigning 1 to an unsigned short is not a problem.
I don't get any warnings with MSVC 2019

C++ Boost matrix error when transforming input to classes

First of all, I use boost library, and if it changes anything, the code is compiled on a Windows Machine.
The code itself contains a lot more of function acting upon matrices but only this one triggers the error.
Well, I am trying to transform matrix like :
{001
100
010}
To something like :
{1
3
2}
But strangely I can't compile my code and I can't find the error so I would be glad if anyone could help me.
Below the code :
using namespace boost::numeric::ublas;
typedef matrix <float, row_major, unbounded_array<float>> MATRIXf;
MATRIXf matrix_to_class (const MATRIXf inputM)
{
MATRIXf output;
for (std::size_t line = 0; line < inputM.size1(); line++)
{
for (std::size_t column = 0; column < inputM.size2(); column++)
{
if (column == 1)
{
output.insert_element(line,0.0,column);
}
}
}
return output;
}
Here is the error code:
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): error C4996: 'std::copy::_Unchecked_iterators::_Deprecate': Call to 'std::copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(2372): note: see declaration of 'std::copy::_Unchecked_iterators::_Deprecate'
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(204): note: see reference to function template instantiation '_OutIt *std::copy<float*,float*>(_InIt,_InIt,_OutIt)' being compiled
1> with
1> [
1> _OutIt=float *,
1> _InIt=float *
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(201): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)'
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(310): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>> &boost::numeric::ublas::unbounded_array<T,std::allocator<T>>::operator =(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(102): note: see reference to class template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>' being compiled
1> with
1> [
1> T=float
1> ]
1> g:\c++ python\travail\visualstudio\visualstudio\guigui\neural net\neural net\utils.hpp(21): note: see reference to class template instantiation 'boost::numeric::ublas::matrix<float,boost::numeric::ublas::row_major,boost::numeric::ublas::unbounded_array<float,std::allocator<T>>>' being compiled
1> with
1> [
1> T=float
1> ]
1>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): error C4996: 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate': Call to 'std::uninitialized_copy' with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'
1> c:\program files (x86)\microsoft visual studio 14.0\vc\include\xmemory(102): note: see declaration of 'std::uninitialized_copy::_Unchecked_iterators::_Deprecate'
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(94): note: see reference to function template instantiation '_FwdIt *std::uninitialized_copy<const float*,float*>(_InIt,_InIt,_FwdIt)' being compiled
1> with
1> [
1> _FwdIt=float *,
1> _InIt=const float *
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\storage.hpp(89): note: while compiling class template member function 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)'
1> with
1> [
1> T=float
1> ]
1> e:\c++ libraries\general\boost_1_65_0\boost\numeric\ublas\matrix.hpp(162): note: see reference to function template instantiation 'boost::numeric::ublas::unbounded_array<float,std::allocator<T>>::unbounded_array(const boost::numeric::ublas::unbounded_array<T,std::allocator<T>> &)' being compiled
1> with
1> [
1> T=float
1> ]
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========
Trying to locate the error brings me to the function above.
Thanks in advance.
Near the end of the first error message is the text, "To disable this warning, use -D_SCL_SECURE_NO_WARNINGS". https://msdn.microsoft.com/en-us/library/ttcz0bys.aspx has a more detailed discussion of warnings and checked iterators. In essence, Microsoft created "safe" mutations of Standard C++ functions to help developers avoid invalid iterator usage. The error message suggests that you define _SCL_SECURE_NO_WARNINGS. This can be done in the project properties C/C++/Preprocessor/Preprocessor Definitions. In a project I worked on in the past, we disabled all the "safe" versions of the functions because of the performance hit.
You may be interested in reading the above Microsoft page for more information about the checked iterator topic.

Boost Optional with Boost Thread compilation issue

My environment is Visual Stuido 2013, VC12, Boost 1.59.
The following code (a minimal repro of the real code):
#include "boost/thread.hpp"
#include "boost/optional.hpp"
class MyClass
{
public:
template <typename T>
operator const T& () const;
};
boost::optional<MyClass> foo()
{
boost::optional<MyClass> res;
return res;
}
int main(int argc)
{
foo();
}
Doesn't compile, the error:
1>------ Build started: Project: TestBoostOptional, Configuration: Debug x64 ------
1> main.cpp
1>c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(297): error C2664: 'void boost::optional_detail::optional_base::construct(MyClass &&)' : cannot convert argument 1 from 'boost::detail::thread_move_t' to 'const MyClass &'
1> with
1> [
1> T=MyClass
1> ]
1> Reason: cannot convert from 'boost::detail::thread_move_t' to 'const MyClass'
1> with
1> [
1> T=MyClass
1> ]
1> No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
1> c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(292) : while compiling class template member function 'boost::optional_detail::optional_base::optional_base(boost::optional_detail::optional_base &&)'
1> with
1> [
1> T=MyClass
1> ]
1> c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(873) : see reference to function template instantiation 'boost::optional_detail::optional_base::optional_base(boost::optional_detail::optional_base &&)' being compiled
1> with
1> [
1> T=MyClass
1> ]
1> c:\workspace\third_party\boost_1_59_0\boost/optional/optional.hpp(766) : see reference to class template instantiation 'boost::optional_detail::optional_base' being compiled
1> with
1> [
1> T=MyClass
1> ]
1> main.cpp(14) : see reference to class template instantiation 'boost::optional' being compiled
Note the #include "boost/thread.hpp". When removing this include the code compiles. Anything that can be done to workaround?
You must define BOOST_THREAD_USES_MOVE before you use any boost header.
#define BOOST_THREAD_USES_MOVE
More information are located here. This define emulates a move by Boost.Move which is necessary here.
In order to implement Movable classes, move parameters and return
types Boost.Thread uses the rvalue reference when the compiler support
it. On compilers not supporting it Boost.Thread uses either the
emulation provided by Boost.Move or the emulation provided by the
previous versions of Boost.Thread depending whether
BOOST_THREAD_USES_MOVE is defined or not. This macros is unset by
default when BOOST_THREAD_VERSION is 2. Since BOOST_THREAD_VERSION 3,
BOOST_THREAD_USES_MOVE is defined.
Also see Boost.Move:
Boost.Thread uses by default an internal move semantic implementation.
Since version 3.0.0 you can use the move emulation emulation provided
by Boost.Move.
When BOOST_THREAD_VERSION==2 define BOOST_THREAD_USES_MOVE if you want
to use Boost.Move interface. When BOOST_THREAD_VERSION==3 define
BOOST_THREAD_DONT_USE_MOVE if you don't want to use Boost.Move
interface.

How can I get rid of gtest compiler warning C4800 ('int' : forcing value to bool 'true' or 'false'")

I've inherited some unit test code (VS2008 c++ for a WinCE-based smart device) that uses gtest. When I compile the unit tests I get all kinds of C4800 warnings about forcing ints into bools. What's weird is that the only gtest calls in the module generating the warnings are to EXPECT_STREQ.
Is this a (minor) bug in gtest, it's doing EXPECT_STREQ in a way that confuses VS2008/WinCE?
We are using gtest version 1.6, does anyone know if version 1.7 works for WinCE?
==============
1>C:\googletest\include\gtest/internal/gtest-port.h(1031) : warning C4800: 'int' : forcing value to bool 'true' or 'false' (performance warning)
1> C:\googletest\include\gtest/internal/gtest-param-util.h(321) : see reference to function template instantiation 'Derived *testing::internal::CheckedDowncastToActualType<const testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator,const testing::internal::ParamIteratorInterface<T>>(Base *)' being compiled
1> with
1> [
1> Derived=const testing::internal::ValuesInIteratorRangeGenerator<ParamType>::Iterator,
1> T=ParamType,
1> Base=const testing::internal::ParamIteratorInterface<bool>
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util.h(314) : while compiling class template member function 'bool testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator::Equals(const testing::internal::ParamIteratorInterface<T> &) const'
1> with
1> [
1> T=ParamType
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util.h(276) : see reference to class template instantiation 'testing::internal::ValuesInIteratorRangeGenerator<T>::Iterator' being compiled
1> with
1> [
1> T=ParamType
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util.h(275) : while compiling class template member function 'testing::internal::ParamIteratorInterface<T> *testing::internal::ValuesInIteratorRangeGenerator<T>::Begin(void) const'
1> with
1> [
1> T=bool
1> ]
1> C:\googletest\include\gtest/gtest-param-test.h(314) : see reference to class template instantiation 'testing::internal::ValuesInIteratorRangeGenerator<T>' being compiled
1> with
1> [
1> T=ParamType
1> ]
1> C:\googletest\include\gtest/gtest-param-test.h(319) : see reference to function template instantiation 'testing::internal::ParamGenerator<T> testing::ValuesIn<const T*>(ForwardIterator,ForwardIterator)' being compiled
1> with
1> [
1> T=bool,
1> ForwardIterator=const bool *
1> ]
1> C:\googletest\include\gtest/internal/gtest-param-util-generated.h(99) : see reference to function template instantiation 'testing::internal::ParamGenerator<T> testing::ValuesIn<T,2>(const T (&)[2])' being compiled
1> with
1> [
1> T=bool
1> ]
1> C:\googletest\include\gtest/gtest-param-test.h(1221) : see reference to function template instantiation 'testing::internal::ValueArray2<T1,T2>::operator testing::internal::ParamGenerator<T>(void) const<bool>' being compiled
1> with
1> [
1> T1=bool,
1> T2=bool,
1> T=bool
1> ]
Warning C4800 is given when an int is put into a variable of type bool. The documentation for warning C4800 states that it is a performance warning so you probably don't have to worry about it.
If you want hide the warning you can use MSVC's #pragma warning(disable:4800) to disable the warning.
So it would look like this
#pragma warning(disable:4800) //Disable the warning
... // Code that gives warning here
#pragma warning(default:4800) //Stop suppressing the warning
You can see the documentation for #pragma warning here.

Boost heterogeneous unit - Bar per Minute

I need to create a unit which represents pressure per time, specifically Bar per Minute.
I tried creating it in the same way as I created similar units before:
typedef boost::units::derived_dimension<boost::units::length_base_dimension, -1,
boost::units::mass_base_dimension, 1,
boost::units::time_base_dimension, -3>::type pressure_roc_dimension;
typedef boost::units::unit<pressure_roc_dimension,
boost::units::make_system<boost::units::metric::bar_base_unit,
boost::units::metric::minute_base_unit>::type> bar_per_minute_unit;
BOOST_UNITS_STATIC_CONSTANT(BarPerMinute, bar_per_minute_unit::unit_type);
typedef boost::units::quantity<bar_per_minute_unit, double> BarPerMinuteRoC;
And then I try to use it:
BarPerMinuteRoC bpm = 5.0 * BarPerMinute;
But this line doesn't compile with quite a long error trail which I'm having a bit of trouble understanding fully.
1>c:\workspace\externals\boost_1_57_0\include\boost\units\detail\linear_algebra.hpp(197): error C2039: 'item' : is not a member of 'boost::units::dimensionless_type'
1> c:\workspace\externals\boost_1_57_0\include\boost\units\dimensionless_type.hpp(37) : see declaration of 'boost::units::dimensionless_type'
1> c:\workspace\externals\boost_1_57_0\include\boost\units\detail\linear_algebra.hpp(259) : see reference to class template instantiation 'boost::units::detail::determine_extra_equations_skip_zeros_impl<true,false>::apply<RowsBegin,1,1,3,Result>' being compiled
1> with
1> [
1> RowsBegin=boost::units::list<boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::detail::make_zero_vector<0>::type>>,boost::units::detail::determine_extra_equations_skip_zeros_impl<false,true>::apply<boost::units::list<boost::units::list<boost::units::static_rational<-1,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::list<boost::units::static_rational<-2,1>,boost::units::detail::expand_dimensions<0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>>>,boost::units::dimensionless_type>,1,0,3,boost::units::list<boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::detail::make_zero_vector<0>::type>>>,boost::units::list<boost::units::list<boost::units::static_rational<-1,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::list<boost::units::static_rational<-2,1>,boost::units::detail::expand_dimensions<0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>>>,boost::units::dimensionless_type>>>::next_equations>
1> , Result=boost::units::list<boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::detail::make_zero_vector<0>::type>>>,boost::units::list<boost::units::list<boost::units::static_rational<-1,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::list<boost::units::static_rational<-2,1>,boost::units::detail::expand_dimensions<0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>>>,boost::units::dimensionless_type>>
1> ]
1> c:\workspace\externals\boost_1_57_0\include\boost\units\detail\linear_algebra.hpp(264) : see reference to class template instantiation 'boost::units::detail::determine_extra_equations<2,false>::apply<boost::units::list<boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::detail::make_zero_vector<0>::type>>,boost::units::detail::determine_extra_equations_skip_zeros_impl<false,true>::apply<boost::units::list<boost::units::list<boost::units::static_rational<-1,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::list<boost::units::static_rational<-2,1>,boost::units::detail::expand_dimensions<0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>>>,boost::units::dimensionless_type>,1,0,3,Result>::next_equations>,3,Result>' being compiled
1> with
1> [
1> Result=boost::units::list<boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::detail::make_zero_vector<0>::type>>>,boost::units::list<boost::units::list<boost::units::static_rational<-1,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::list<boost::units::static_rational<-2,1>,boost::units::detail::expand_dimensions<0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>>>,boost::units::dimensionless_type>>
1> ]
1> c:\workspace\externals\boost_1_57_0\include\boost\units\detail\linear_algebra.hpp(538) : see reference to class template instantiation 'boost::units::detail::determine_extra_equations<3,false>::apply<Matrix,3,Matrix>' being compiled
1> with
1> [
1> Matrix=boost::units::list<boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::detail::make_zero_vector<0>::type>>>,boost::units::list<boost::units::list<boost::units::static_rational<-1,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::list<boost::units::static_rational<-2,1>,boost::units::detail::expand_dimensions<0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>>>,boost::units::dimensionless_type>>
1> ]
1> c:\workspace\externals\boost_1_57_0\include\boost\units\detail\linear_algebra.hpp(828) : see reference to class template instantiation 'boost::units::detail::make_square_and_invert<boost::units::list<boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<0,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::detail::make_zero_vector<0>::type>>>,boost::units::list<boost::units::list<boost::units::static_rational<-1,1>,boost::units::list<boost::units::static_rational<1,1>,boost::units::list<boost::units::static_rational<-2,1>,boost::units::detail::expand_dimensions<0>::apply<boost::units::dimensionless_type,boost::units::dimensionless_type>::type>>>,boost::units::dimensionless_type>>>' being compiled
1> c:\workspace\externals\boost_1_57_0\include\boost\units\detail\linear_algebra.hpp(1032) : see reference to class template instantiation 'boost::units::detail::normalize_units<T>' being compiled
1> with
1> [
1> T=boost::units::list<boost::units::scaled_base_unit<boost::units::si::second_base_unit,boost::units::scale<60,boost::units::static_rational<1,1>>>,boost::units::list<boost::units::metric::bar_base_unit,boost::units::dimensionless_type>>
1> ]
1> c:\workspace\externals\boost_1_57_0\include\boost\units\detail\linear_algebra.hpp(1051) : see reference to class template instantiation 'boost::units::detail::calculate_base_unit_exponents_impl<false>::apply<T,Dimensions>' being compiled
1> with
1> [
1> T=boost::units::list<boost::units::scaled_base_unit<boost::units::si::second_base_unit,boost::units::scale<60,boost::units::static_rational<1,1>>>,boost::units::list<boost::units::metric::bar_base_unit,boost::units::dimensionless_type>>
1> , Dimensions=BSII::Units::pressure_roc_dimension
1> ]
1> c:\workspace\externals\boost_1_57_0\include\boost\units\heterogeneous_system.hpp(243) : see reference to class template instantiation 'boost::units::detail::calculate_base_unit_exponents<boost::units::list<boost::units::scaled_base_unit<boost::units::si::second_base_unit,boost::units::scale<60,boost::units::static_rational<1,1>>>,boost::units::list<T,boost::units::dimensionless_type>>,Dimensions>' being compiled
1> with
1> [
1> T=boost::units::metric::bar_base_unit
1> , Dimensions=BSII::Units::pressure_roc_dimension
1> ]
1> c:\workspace\externals\boost_1_57_0\include\boost\units\unit.hpp(92) : see reference to class template instantiation 'boost::units::detail::make_heterogeneous_system<Dim,System>' being compiled
1> with
1> [
1> Dim=BSII::Units::pressure_roc_dimension
1> , System=boost::units::homogeneous_system<boost::units::list<boost::units::scaled_base_unit<boost::units::si::second_base_unit,boost::units::scale<60,boost::units::static_rational<1,1>>>,boost::units::list<boost::units::metric::bar_base_unit,boost::units::dimensionless_type>>>
1> ]
1> c:\workspace\externals\boost_1_57_0\include\boost\units\unit.hpp(99) : see reference to class template instantiation 'boost::units::reduce_unit<S1>' being compiled
1> with
1> [
1> S1=BSII::Units::bar_per_minute_unit
1> ]
1> c:\workspace\foundations\sw_foundations\bsii_common\test\src\units\units_pressure_test.cpp(97) : see reference to class template instantiation 'boost::units::is_implicitly_convertible<BSII::Units::bar_per_minute_unit,Unit>' being compiled
1> with
1> [
1> Unit=BSII::Units::bar_per_minute_unit
1> ]
According to the Boost documentation a homogeneous system can only be composed of linearly independent base units. In my case, I'm trying to mix bars (which in turn "contain" seconds as the time element) with minutes. This sounds problematic to me. But on the other hand, since I don't include mass and length base units in my system it seems to me that the base is independent after all.
In any case, I searched online for an example of creating such a heterogeneous unit but didn't find anything comprehensible. Also, I read in the Boost documentation that a heterogeneous unit doesn't perserve information about how it was created. Does this mean I won't be able to, for instance, multiply BarPerMinuteRoC by Minute and get Bar back?
This is a bug in the library. Your code ought to work and it does in the current GIT develop branch.