接続数

COUNTER379628FROM 2012/5/16

MISRA-C diary(C言語日誌)

MISRA-C >> Article details

2014/06/18

cpp2011//20.6.8 Allocator traits

Tweet ThisSend to Facebook | by kaizen
// 1 filename:cpp2011-20-6-8.cpp
// ver 0.1 June.12, 2014
//
// 2 original examples and/or notes:
// (c) ISO/IEC JTC1 SC22 WG21 N3242, April 12, 2011
// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2011/n3242.pdf
// >20 General utilities library 20.6 Memory 20.6.8 Allocator traits
//
// 3 compile and output mechanism:
// (c) Dr. OGAWA Kiyoshi, kaizen at gifu-u.ac.jp
// http://sourceforge.jp/users/kaizen/pf/CPP2011/files/
// http://researchmap.jp/kaizen/MISRA-C/
//
// 4 compile errors and/or warnings:
// 4.1(c) Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
// Target: x86_64-apple-darwin13.2.0,  Thread model: posix
// Command/Options: c++ -std=c++11 -stdlib=libc++ -Wall cpp2011-20-6-8.cpp  
// (c) LLVM 2003-2009 University of Illinois at Urbana-Champaign.

// 4.2. g++-4.9 (GCC) 4.9.0 20131229 (experimental)
// Copyright (C) 2013 Free Software Foundation, Inc.
// This is free software; see the source for copying conditions.  
// There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// http://gcc.gnu.org/onlinedocs/gcc/Standards.html
// Command/Options: g++-4.9  -std=c++11  -Wall cpp2011-20-6-8.cpp 
// g++-4.9: error: unrecognized command line option '-stdlib=libc++'
// Configuration:brew install gcc49
//
// 4.3. Visual Studio Express 2013, 
// (c) Microsoft http://www.visualstudio.com/
// SPEC:
// Windows 7, .NET Framework
// (c) VMware, Inc.
// VMWare fusion 6
//
// 5. Hardware:  MacBook Pro, 
//(c) Intel http://ark.intel.com/products/37006/
//Core 2 Duo 2.53GHz, 8GB, 1067MHz DDR3
//
// 6. Special Thanks: Upper organizatios and 
// ITSCJ/IPSJ http://www.itscj.ipsj.or.jp/itscj_english/index.html
// Renesas Electronics Corporation.http://www.renesas.com/
// NPO SESSAME project, http://www.sessame.jp/workinggroup/WorkingGroup3/
// Toyo Corporation, http://www.toyo.co.jp/English/
// Japan Standard Association, http://bit.ly/1lzykg1
// NPO TOPPERS project, https://www.toppers.jp/asp-d-download.html
// Daido Universcity, http://www.daido-it.ac.jp/gakubugakka/computer/index.html
// WITZ Co.Ltd., http://www.witz-inc.co.jp/products/solution/solution.html
// SevenWise.co., http://www.7ws.co.jp/index.html
// TOYOTA Motor Corporation, http://toyota.jp/
// IT planning Inc., http://www.itpl.co.jp/en/index.html
// DENSO Corporation, http://www.globaldenso.com/en/
// Aisin Seiki co. Ltd., http://www.aisin.com/
// Spancion Inc., http://www.spansion.com/
// Yazaki Corporation, http://www.yazaki-group.com/global/
// Pananosic Corporation, http://www.panasonic.net/
// SWEST: Summer Workshop on Embedded System Technologies , http://swest.toppers.jp
// CEST: Consortium for Embedded System Technology, http://www.ertl.jp/CEST/
// JUSE: Union of Japanese Scientists and Engineers, http://www.juse.or.jp/e/
// OSC:Open Source Conference, http://www.ospn.jp/
//

//#include <cstdlib>
//#include <assert.h>
//#include <array>
//#include <algorithm>
//#include <bitset>
//#include <cmath>
//#include <complex>
//#include <ccomplex>
//#include <cstdint>
//#include <cstring>
//#include <cassert>
//#include <exception>
//#include <iosfwd>
#include <iostream>
//#include <iterator>
//#include <initializer_list>
//#include <limits>
//#include <memory>
//#include <string.h>
//#include <tupple>
//#include <typeinfo>
//#include <type_traits>
//#include <utility>

namespace std {
// 20.6.3, pointer traits
template <class Ptr> struct pointer_traits;
template <class T> struct pointer_traits<T*>;
// 20.6.4, pointer safety
//error: enum class pointer_safety { relaxed, preferred, strict };  //error: reference to 'pointer_safety' is ambiguous
void declare_reachable(void *p);
template <class T> T *undeclare_reachable(T *p) noexcept;
void declare_no_pointers(char *p, size_t n) noexcept;
void undeclare_no_pointers(char *p, size_t n) noexcept;
pointer_safety get_pointer_safety() noexcept;
// 20.6.5, pointer alignment function
void *align(std::size_t alignment, std::size_t size,
void *&ptr, std::size_t& space) noexcept;
// 20.6.6, allocator argument tag
struct allocator_arg_t { };
constexpr allocator_arg_t allocator_arg = allocator_arg_t();
// 20.6.7, uses_allocator
template <class T, class Alloc> struct uses_allocator;
// 20.6.8, allocator traits
template <class Alloc> struct allocator_traits;
template <class Alloc> struct allocator_traits {
typedef Alloc allocator_type;
typedef typename Alloc::value_type value_type;
typedef value_type* pointer;//see below
typedef pointer_traits<pointer>::rebind const_pointer;//
typedef Alloc::void_pointer void_pointer;//pointer_traits<pointer>::rebind<void>.
typedef Alloc::const_void_pointer const_void_pointer;//pointer_traits<pointer>::rebind<constvoid>.
typedef Alloc::difference_type difference_type;//pointer_traits<pointer>::difference_type.
typedef Alloc::size_type size_type;//make_unsigned<difference_type>::type
typedef Alloc::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;//false_type.
typedef Alloc::propagate_on_container_move_assignment propagate_on_container_move_assignment;//false_type.
typedef Alloc::propagate_on_container_swappropagate_on_container_swap;//false_type.
template <class T> using rebind_alloc = Alloc::rebind<T>::other;//Alloc<T, Args>
template <class T> using rebind_traits = allocator_traits<rebind_alloc<T> >;
static pointer allocate(Alloc& a, size_type n);
static pointer allocate(Alloc& a, size_type n, const_void_pointer hint);
static void deallocate(Alloc& a, pointer p, size_type n) noexcept;
template <class T, class... Args>
static void construct(Alloc& a, T* p, Args&&... args);
template <class T>
static void destroy(Alloc& a, T* p);
static size_type max_size(const Alloc& a);
static Alloc select_on_container_copy_construction(const Alloc& rhs);
};
}
//20.6.8.1 Allocator traits member types [allocator.traits.types]
//typedef see below pointer;
//1 Type: Alloc::pointer if such a type exists; otherwise, value_type*.
//typedef see below const_pointer;
//2 Type: Alloc::const_pointer if such a type exists; otherwise, pointer_traits<pointer>::rebind<constvalue_type>.
//typedef see below void_pointer;
//3 Type: Alloc::void_pointer if such a type exists; otherwise, pointer_traits<pointer>::rebind<void>.
//typedef see below const_void_pointer;
//4 Type: Alloc::const_void_pointer if such a type exists; otherwise, pointer_traits<pointer>::rebind<constvoid>.
//typedef see below difference_type;
//5 Type: Alloc::difference_type if such a type exists; otherwise, pointer_traits<pointer>::difference_type.
//typedef see below size_type;
//6 Type: Alloc::size_type if such a type exists; otherwise, make_unsigned<difference_type>::type.
//typedef see below propagate_on_container_copy_assignment;
//7 Type: Alloc::propagate_on_container_copy_assignment if such a type exits, otherwise false_type.
//typedef see below propagate_on_container_move_assignment;
//8 Type: Alloc::propagate_on_container_move_assignment if such a type exits, otherwise false_type.
//typedef see below propagate_on_container_swap;
//9 Type: Alloc::propagate_on_container_swap if such a type exits, otherwise false_type.
//template <class T> using rebind_alloc = see below;
//10 Alias template: Alloc::rebind<T>::other if such a type exists; otherwise, Alloc<T, Args> if Alloc is a class template instantiation of the form Alloc<U, Args>, where Args is zero or more type arguments; otherwise, the instantiation of rebind_alloc is ill-formed.
//20.6.8.2 Allocator traits static member functions [allocator.traits.members]
//static pointer allocate(Alloc& a, size_type n);
//1 Returns: a.allocate(n).
//static pointer allocate(Alloc& a, size_type n, const_void_pointer hint);
//2 Returns: a.allocate(n, hint) if that expression is well-formed; otherwise, a.allocate(n).
//static void deallocate(Alloc& a, pointer p, size_type n) noexcept;
//3 Effects: calls a.deallocate(p, n).
//template <class T, class... Args>
//static void construct(Alloc& a, T* p, Args&&... args);
//4 Effects: calls a.construct(p, std::forward<Args>(args)...) if that call is well-formed; otherwise,invokes ::new (static_cast<void*>(p)) T(std::forward<Args>(args)...).
//template <class T>
//static void destroy(Alloc& a, T* p);
//5 Effects: calls a.destroy(p) if that call is well-formed; otherwise, invokes p->~T().
//static size_type max_size(Alloc& a);
//6 Returns: a.max_size() if that expression is well-formed; otherwise, numeric_limits<size_type>::max().
//static Alloc select_on_container_copy_construction(const Alloc& rhs);
//7 Returns: rhs.select_on_container_copy_construction() if that expression is well-formed; otherwise,rhs.


using namespace std;

int main() {
cout << "20 General utilities library 20.6 Memory 20.6.8 Allocator traits"<<std::endl;
return 0;
}
// 1.error
// c++ -std=c++11 -stdlib=libc++ -Wall cpp2011-20-6-8.cpp
cpp2011-20-6-8.cpp:110:9: error: missing 'typename' prior to dependent type name 'pointer_traits<pointer>::rebind'
typedef pointer_traits<pointer>::rebind const_pointer;//
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        typename 
cpp2011-20-6-8.cpp:111:9: error: missing 'typename' prior to dependent type name 'Alloc::void_pointer'
typedef Alloc::void_pointer void_pointer;//pointer_traits<pointer>::rebind<void>.
        ^~~~~~~~~~~~~~~~~~~
        typename 
cpp2011-20-6-8.cpp:112:9: error: missing 'typename' prior to dependent type name 'Alloc::const_void_pointer'
typedef Alloc::const_void_pointer const_void_pointer;//pointer_traits<pointer>::rebind<constvoid>.
        ^~~~~~~~~~~~~~~~~~~~~~~~~
        typename 
cpp2011-20-6-8.cpp:113:9: error: missing 'typename' prior to dependent type name 'Alloc::difference_type'
typedef Alloc::difference_type difference_type;//pointer_traits<pointer>::difference_type.
        ^~~~~~~~~~~~~~~~~~~~~~
        typename 
cpp2011-20-6-8.cpp:114:9: error: missing 'typename' prior to dependent type name 'Alloc::size_type'
typedef Alloc::size_type size_type;//make_unsigned<difference_type>::type
        ^~~~~~~~~~~~~~~~
        typename 
cpp2011-20-6-8.cpp:115:9: error: missing 'typename' prior to dependent type name 'Alloc::propagate_on_container_copy_assignment'
typedef Alloc::propagate_on_container_copy_assignment propagate_on_container_copy_assignment;//false_type.
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        typename 
cpp2011-20-6-8.cpp:116:9: error: missing 'typename' prior to dependent type name 'Alloc::propagate_on_container_move_assignment'
typedef Alloc::propagate_on_container_move_assignment propagate_on_container_move_assignment;//false_type.
        ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
        typename 
cpp2011-20-6-8.cpp:117:16: error: nested name specifier 'Alloc::' for declaration does not refer into a class, class template or class template
      partial specialization
typedef Alloc::propagate_on_container_swappropagate_on_container_swap;//false_type.
        ~~~~~~~^
cpp2011-20-6-8.cpp:118:48: error: use 'template' keyword to treat 'rebind' as a dependent template name
template <class T> using rebind_alloc = Alloc::rebind<T>::other;//Alloc<T, Args>
                                               ^
                                               template 
cpp2011-20-6-8.cpp:118:41: error: missing 'typename' prior to dependent type name 'Alloc::Alloc::rebind<T>::other'
template <class T> using rebind_alloc = Alloc::rebind<T>::other;//Alloc<T, Args>
                                        ^~~~~~~~~~~~~~~~~~~~~~~
                                        typename 
10 errors generated.


18:29 | Impressed! | Voted(0) | Comment(0)