c++11

Nested class access to enclosing class members

六眼飞鱼酱① 提交于 2021-02-20 04:14:33
问题 From C++ Primer 5th edition By Stanley Lippman et al(19.5): A nested class can have the same kinds of members as a nonnested class. Just like any other class, a nested class controls access to its own members using access specifiers. The enclosing class has no special access to the members of a nested class, and the nested class has no special access to members of its enclosing class . Is there any truth to the bolded part? I could find no mention of the nested class being restricted access

Nested class access to enclosing class members

泄露秘密 提交于 2021-02-20 04:12:54
问题 From C++ Primer 5th edition By Stanley Lippman et al(19.5): A nested class can have the same kinds of members as a nonnested class. Just like any other class, a nested class controls access to its own members using access specifiers. The enclosing class has no special access to the members of a nested class, and the nested class has no special access to members of its enclosing class . Is there any truth to the bolded part? I could find no mention of the nested class being restricted access

Libtorch works with g++, but fails with Intel compiler

霸气de小男生 提交于 2021-02-19 09:31:23
问题 I want to use a neural network developed in Python (PyTorch) in a Fortran program. My OS is Ubuntu 18.04. What I am doing: save it as torchscript: TurbNN.pt call it from c++ program: call_ts.cpp, call_ts.h call c++ program from Fortran program (using bind©): main.f90 I successfully compiled the codes using CMake (3.19.4) and g++ (7.5.0). However, I cannot compile them using Intel compilers (HPCKit 2021.1.0.2684): # downloaded torchlib export Torch_DIR=/home/aiskhak/nn/fortran_calls

Sublime Text 2 Run C++11 Code

冷暖自知 提交于 2021-02-19 08:40:08
问题 I have the following code in Sublime Text 2: #include <iostream> #include <string> using std::cout; using std::string; int main() { string s("some string"); if (s.begin() != s.end()) // make sure s is not empty { auto it = s.begin(); // it denotes the first character in s *it = toupper(*it); // make that character uppercase } cout << s; return 0; } I can build C++11 code in Sublime by pressing ctrl-B as I changed my C++.sublime-build file to "cmd": ["g++", "-std=c++11", "${file}", "-o", "$

c++ log functions using template SFINAE for conditional compile

前提是你 提交于 2021-02-19 08:34:44
问题 I am evaluating if it is possible to leverage C++11 features to replace logging Macros without any run-time additional cost. I come out with this demo: enum class LogLevel { Fatal = 0, DFatal = 1, Error = 2, Normal = 3, Verbose = 4, Debug = 5 }; constexpr LogLevel log_compiled = LogLevel::Normal; LogLevel log_runtime = LogLevel::Error; #ifdef NDEBUG constexpr LogLevel log_fatal = LogLevel::Fatal; #else constexpr LogLevel log_fatal = LogLevel::DFatal; #endif template <LogLevel L, typename std:

std::unordered_map, can you access the elements in a bucket with its bucket number? [duplicate]

纵饮孤独 提交于 2021-02-19 08:01:10
问题 This question already has an answer here : C++11 get all items of one bucket in a unordered_map (1 answer) Closed 5 years ago . for std::unordered_map , can you access the elements in some bucket i if its bucket_size is not zero? 回答1: The answer is to use std::unordered_map::begin(bucket_num) or std::unordered_map::cbegin(bucket_num) to get the iterator pointing to the the first element to that bucket and iterate to the end of the bucket std::unordered_map::end(bucket_num) for ( auto it = u

std::unordered_map, can you access the elements in a bucket with its bucket number? [duplicate]

社会主义新天地 提交于 2021-02-19 08:01:09
问题 This question already has an answer here : C++11 get all items of one bucket in a unordered_map (1 answer) Closed 5 years ago . for std::unordered_map , can you access the elements in some bucket i if its bucket_size is not zero? 回答1: The answer is to use std::unordered_map::begin(bucket_num) or std::unordered_map::cbegin(bucket_num) to get the iterator pointing to the the first element to that bucket and iterate to the end of the bucket std::unordered_map::end(bucket_num) for ( auto it = u

Macro-based counter

倖福魔咒の 提交于 2021-02-19 07:43:26
问题 Is it possible to create compile time constants like this: // event.h #define REGISTER_EVENT_TYPE() ... // Returns last_returned_number+1 // header1 #define SOME_EVENT REGISTER_EVENT_TYPE() // header2 #define SOME_OTHER_EVENT REGISTER_EVENT_TYPE() Where SOME_EVENT will be 0 and SOME_OTHER_EVENT will be 1. Tried the following code: #define DEF_X(x) const int x = BOOST_PP_COUNTER; #define REGISTER_EVENT_TYPE(x) BOOST_PP_UPDATE_COUNTER()DEF_X(x) #include REGISTER_EVENT_TYPE(SOME_EVENT_TYPE) But

Macro-based counter

狂风中的少年 提交于 2021-02-19 07:43:25
问题 Is it possible to create compile time constants like this: // event.h #define REGISTER_EVENT_TYPE() ... // Returns last_returned_number+1 // header1 #define SOME_EVENT REGISTER_EVENT_TYPE() // header2 #define SOME_OTHER_EVENT REGISTER_EVENT_TYPE() Where SOME_EVENT will be 0 and SOME_OTHER_EVENT will be 1. Tried the following code: #define DEF_X(x) const int x = BOOST_PP_COUNTER; #define REGISTER_EVENT_TYPE(x) BOOST_PP_UPDATE_COUNTER()DEF_X(x) #include REGISTER_EVENT_TYPE(SOME_EVENT_TYPE) But

Multiple definition of namespace::variable even using ifndef

十年热恋 提交于 2021-02-19 07:40:07
问题 I know I must be doing something wrong here. rank.h #ifndef RANK_H #define RANK_H namespace mmi { int chunk; void rank(int my_rank); } #endif rank.cpp #include "rank.h" namespace mmi { //do something with chunk } main.cpp #include "rank.h" int main() { mmi::chunk = 1; } And the output of compilation; g++ -g -Wall -std=gnu++11 -c -o main.o main.cpp g++ -g -Wall -std=gnu++11 -c -o rank.o rank.cpp mpic++ main.o rank.o -o main rank.o:(.bss+0x0): multiple definition of `mmi::chunk' main.o:(.bss