ERROR C2993: when compile boost-1_72 with visual studio 2019 errors occur in vector.hpp file - boost

I'm trying to compile a library which depends on boost-1_72 with visual studio 2019, but error occurs in vector.hpp file. the error is C2993 'J' is not a valid type for non-type template parameter 'J' at line 245, and another error is C4430 missing type specifier - int assumed.Note:C++ does not support default-int at line 252.
private:
template <std::size_t J>
using store_at = decltype(store_at_impl(static_cast<vector_data*>(nullptr)));
public:
template <typename J>
BOOST_CXX14_CONSTEXPR BOOST_FUSION_GPU_ENABLED
typename store_at<J::value>::elem_type& at_impl(J)
{
return store_at<J::value>::elem;
}
template <typename J>
BOOST_CONSTEXPR BOOST_FUSION_GPU_ENABLED
typename store_at<J::value>::elem_type const& at_impl(J) const
{
return store_at<J::value>::elem;
}
};
} // namespace boost::fusion::vector_detail

Related

Can't define std::function variable from the virtual method pointer in vs2013

In my project I am trying to define std::function variable from the virtual method pointer:
#include <functional>
class VirtualClass
{
public:
virtual void foo(int x) = 0;
};
class DerivedClass : public VirtualClass
{
public:
virtual void foo(int x) override
{
// I am foo from DerivedClass;
}
};
int main()
{
DerivedClass derivedClass;
std::function<void(VirtualClass&, int)> fooFunc = &VirtualClass::foo; //doesn't compile
fooFunc(derivedClass, 0);
return 0;
}
This code is compiling in visual studio 2017, but doesn't compile in visual studio 2013. Is it possible to fix a compilation error in vs 2013 without switching to pure pointers and keep using std::function?
update:
the error message is the following:
Error 1 error C2664: 'void std::_Func_class<_Ret,VirtualClass &,int>::_Set(std::_Func_base<_Ret,VirtualClass &,int> *)' : cannot convert argument 1 from '_Myimpl *' to 'std::_Func_base<_Ret,VirtualClass &,int> *' c:\program files (x86)\microsoft visual studio 12.0\vc\include\functional 506 1 ConsoleApplication1

Templated Struct in C++

I have a Struct with Template and there is error at constructor at Structure.
I have developed the code with VS2012, now open the project with VS2015 and I have this issue.
How can I fix it?
template<typename It>
Rect_< typename VT<typename VT<It>::value_type>::value_type > BoundingRect(It Begin,It End,int inc=0)
{
typedef typename VT<typename VT<It>::value_type>::value_type T;
struct M{
T x,X,y,Y;
M():x(std::numeric_limits<T>::max()),X(-x),y(x),Y(X){}
void operator()(const VT<It>::value_type v)
{
if(x>v.x) x=v.x;
if(X<v.x) X=v.x;
if(y>v.y) y=v.y;
if(Y<v.y) Y=v.y;
}
};
const M m( std::for_each(Begin,End,M()) );
return inc? Rect_<T>( m.x-inc, m.y-inc, m.X-m.x+inc*2, m.Y-m.y+inc*2 ):Rect_<T>( m.x, m.y, m.X-m.x, m.Y-m.y );
}
The error is at this line
M():x(std::numeric_limits<T>::max()),X(-x),y(x),Y(X){}
as C2589 '(':illegal token on right side of '::'
C2059 syntax error: ':
How to fix the errors?
:'

Intellisense PCH Warning: Header stop not at file scope. An intellisense PCH file was not generated

When I open my file on MSVS 2017, I get this error from intellisense:
Intellisense PCH Warning: Header stop not at file scope. An intellisense PCH file was not generated
I don't know why I'm getting this error, I turned off precompiled headers, and I have #pragma once at the beginning. The end of file is at the global scope and not in a macro. I have added the /clr switch to my compilation options. My code:
#pragma once
// v0.2
#include<string>
namespace marshal {
template <typename Out, typename In>
static Out cast(In val) {
return In::operator Out(val);
}
template<>
static std::string cast(System::String^ val) {
using namespace System::Runtime::InteropServices;
const char* chars =
(const char*)(Marshal::StringToHGlobalAnsi(val)).ToPointer();
std::string os = chars;
Marshal::FreeHGlobal(System::IntPtr((void*)chars));
return os;
}
template<>
static System::String^ cast(std::string val) {
return gcnew System::String(val.c_str());
}
}
I'm getting this error at the last bracket. (line 27)

Why does failed enable_if lead to compile time error?

I want to disable copy constructor of some template class conditionally. In other words, I want disable copy constructor, if base type is not copy constructible. To solve such problem (in educational purposes) I decided to write following program. (Here is link to ideone https://ideone.com/QY0NHJ) Below is source of my program:
#include <algorithm>
#include <type_traits>
using namespace std;
template <typename Data>
class Container
{
public:
typedef Container<Data> self_type;
Container():
m_data()
{
}
Container(const typename
std::enable_if<std::is_copy_constructible<Data>::value,
self_type>::type& other_data) :
m_data(other_data.m_data)
{
}
Container(self_type&& other)
{
std::swap(m_data, other.m_data);
}
private:
Data m_data;
};
class SomeData
{
public:
SomeData(){}
SomeData(const SomeData&) = delete;
};
int main()
{
Container<SomeData> container;
return 0;
}
But message from compiler really confuses me:
prog.cpp: In instantiation of ‘class Container’:
prog.cpp:41:22: required from here
prog.cpp:17:2: error: no type named ‘type’ in ‘struct std::enable_if >’
Container(const typename std::enable_if::value
As I understand it should lead to SFINAE and nothing should be arised from compiler. Where am I wrong?
As I understand it should lead to SFINAE
SFINAE means "substitution failure is not an error". You need substitution to occur in order to SFINAE out something. In this case, it is sufficient to add a default template parameter to your copy constructor:
template <typename D = Data>
Container(const typename std::enable_if<std::is_copy_constructible<D>::value,
self_type>::type& other_data) :
m_data(other_data.m_data)
{
}
live example on wandbox

IntelliSense: redeclaration of alias template

IntelliSense in the Visual Studio 2017 (15.1) underlines the word Type in the following code:
#include <type_traits>
template<class... Vars>
struct Test : std::true_type { };
template<class... TT>
using Type /*!*/ = std::conditional_t<std::conjunction_v<Test<TT>...>, int, double>;
//template<class... TT>
//using Type = std::conditional_t<std::conjunction<Test<TT>...>::value, int, double>; // no error
int main()
{
return 0;
}
The error reads (with some obvious omissions): alias template type "std::conditional_t<...>" is incompatible with the previous type of "std::conditional_t<...>" in the redeclaration of alias template "Type".
The code compiles. Is it a bug in IntelliSense?

Resources