templates

Loading javascript in Code Igniter

大兔子大兔子 提交于 2021-02-08 02:11:00
问题 For our Code Igniter application we are loading all of our javascript just before the closing body tag. so in our controllers we have $this->load->view('head', $this->head); $this->load->view('main_view_for_controller', $data); $this->load->view('foot', $this->foot); And in the foot view we have a bunch of <script src="master.js"></script> tags. These include jQuery jQuery-ui shared-functions Now this works great, until you think about JS used only on specific pages, or inline js. You can't

Loading javascript in Code Igniter

筅森魡賤 提交于 2021-02-08 02:08:33
问题 For our Code Igniter application we are loading all of our javascript just before the closing body tag. so in our controllers we have $this->load->view('head', $this->head); $this->load->view('main_view_for_controller', $data); $this->load->view('foot', $this->foot); And in the foot view we have a bunch of <script src="master.js"></script> tags. These include jQuery jQuery-ui shared-functions Now this works great, until you think about JS used only on specific pages, or inline js. You can't

Allocator specialized for array types in c++14?

谁都会走 提交于 2021-02-08 01:26:41
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

那年仲夏 提交于 2021-02-08 01:24:22
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

落爺英雄遲暮 提交于 2021-02-08 01:23:08
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Allocator specialized for array types in c++14?

孤人 提交于 2021-02-08 01:22:35
问题 Why isn't there an array template specialization for std::allocator<T[]> in c++14? When playing around trying to specialize std::allocator<T[]> myself I hit a dead-end when implementing the construct() and destroy() method. Is this the reason? Why then have construct() and destroy() part of std::allocator<>? template <T> class allocator <T[]> { // ...most is similar for std::allocator<>... template <class U, class... Args> void construct( U *p, Args&&.. args) { // what to write for array

Do `const T` and `T` have no difference when taking its nested type?

。_饼干妹妹 提交于 2021-02-07 18:44:00
问题 #include <string> template<typename T, typename C, typename CR> void f() { typename T::size_type* p1{}; // ok typename CR::size_type* p2{}; // error typename C::size_type* p3{}; // Does the C++ standard allow this? } int main() { f<std::string, const std::string, const std::string&>(); } Do const T and T have no difference when taking its nested type? 回答1: Indeed, the "nested types" are the same. A type qualified with const and/or volatile is a "version" of the unqualified type ([basic.type

template Base Class initialization

谁说我不能喝 提交于 2021-02-07 18:26:48
问题 while in visual c++ the code below is accepted, g++ will generate the error: "class Derived does not have any field name Base" which is following the standard? template <class T> class Base { public: Base(){}; }; template <class T> class Derived:public Base<T> { public: Derived():Base(){} }; BTW: both accept Derived():Base<T>(){} so meantime, I will follow gcc 回答1: MSVC++ is not correct. Base is a template, not a type. Note that in the usual case, Base is looked up in the scope of Derived<T>

C++ compile time check if method exists in template type

一世执手 提交于 2021-02-07 14:16:47
问题 I have a template that calls a member function. How do I check with static_assert that the method exists? struct A { }; struct B { int foo() { return 42; } }; template <typename T> struct D { static_assert(/* T has foo */, "T needs foo for reasons"); int bar() { return t.foo(); } T t; }; int main() { D<A> d; std::cout << d.bar() << std::endl; return 0; } I know this will just generate a compiler error that A does not have foo but I would like to check and give a better error output using

C++: Can I have non-static member variable templates?

我是研究僧i 提交于 2021-02-07 14:14:51
问题 I'm trying to write a bit of code that requires me to have a lot of std::array s in a container class. These arrays are all of varying sizes (all consecutive from 2-16, if that matters), and there is exactly one of each size. I want to put them in a container class, and be able to access them with templates. It's probably easier to explain with code. I want something like this: class ContainerClass { public: // I want to declare some number of arrays right here, all of different // sizes,