Search results
Top results related to what are some uses of a storage area network example worksheet
Top Answer
Answered May 23, 2017 · 247 votes
Return type forwarding in generic code
For non-generic code, like the initial example you gave, you can manually select to get a reference as a return type:
auto const& Example(int const& i) { return i; }
but in generic code you want to be able to perfectly forward a return type without knowing whether you are dealing with a reference or a value. decltype(auto) gives you that ability:
template<class Fun, class... Args>decltype(auto) Example(Fun fun, Args&&... args) { return fun(std::forward<Args>(args)...); }
Delaying return type deduction in recursive templates
In this Q&A a few days ago, an infinite recursion during template instantiation was encountered when the return type of the template was specified as decltype(iter(Int<i-1>{})) instead of decltype(auto).
template<int i> struct Int {};-constexpr auto iter(Int<0>) -> Int<0>;template<int i>constexpr auto iter(Int<i>) -> decltype(auto) { return iter(Int<i-1>{}); }int main() { decltype(iter(Int<10>{})) a; }
decltype(auto) is used here to delay the return type deduction after the dust of template instantiation has settled.
Other uses
You can also use decltype(auto) in other contexts, e.g. the draft Standard N3936 also states
7.1.6.4 auto specifier [dcl.spec.auto]
1 The auto and decltype(auto) type-specifiers designate a placeholder type that will be replaced later, either by deduction from an initializer or by explicit specification with a trailing-return-type. The auto type-specifier is also used to signify that a lambda is a generic lambda.
2 The placeholder type can appear with a function declarator in the decl-specifier-seq, type-specifier-seq, conversion-function-id, or trailing-return-type, in any context where such a declarator is valid. If the function declarator includes a trailing-return-type (8.3.5), that specifies the declared return type of the function. If the declared return type of the function contains a placeholder type, the return type of the function is deduced from return statements in the body of the function, if any.
The draft also contains this example of variable initialization:
int i;int&& f();auto x3a = i; // decltype(x3a) is intdecltype(auto) x3d = i; // decltype(x3d) is intauto x4a = (i); // decltype(x4a) is intdecltype(auto) x4d = (i); // decltype(x4d) is int&auto x5a = f(); // decltype(x5a) is intdecltype(auto) x5d = f(); // decltype(x5d) is int&&auto x6a = { 1, 2 }; // decltype(x6a) is std::initializer_list<int>decltype(auto) x6d = { 1, 2 }; // error, { 1, 2 } is not an expressionauto *x7a = &i; // decltype(x7a) is int*decltype(auto)*x7d = &i; // error, declared type is not plain decltype(auto)
1/5
Top Answer
Answered Oct 18, 2019 · 279 votes
I think you need to use template template syntax to pass a parameter whose type is a template dependent on another template like this:
template <template<class> class H, class S>void f(const H<S> &value) {}-
Here, H is a template, but I wanted this function to deal with all specializations of H.
NOTE: I've been programming c++ for many years and have only needed this once. I find that it is a rarely needed feature (of course handy when you need it!).
I've been trying to think of good examples, and to be honest, most of the time this isn't necessary, but let's contrive an example. Let's pretend that std::vector doesn't have a typedef value_type.
So how would you write a function which can create variables of the right type for the vectors elements? This would work.
template <template<class, class> class V, class T, class A>void f(V<T, A> &v) { // This can be "typename V<T, A>::value_type", // but we are pretending we don't have it T temp = v.back(); v.pop_back(); // Do some work on temp std::cout << temp << std::endl;}
NOTE: std::vector has two template parameters, type, and allocator, so we had to accept both of them. Fortunately, because of type deduction, we won't need to write out the exact type explicitly.
which you can use like this:
f<std::vector, int>(v); // v is of type std::vector<int> using any allocator-
or better yet, we can just use:
f(v); // everything is deduced, f can deal with a vector of any type!-
UPDATE: Even this contrived example, while illustrative, is no longer an amazing example due to c++11 introducing auto. Now the same function can be written as:
template <class Cont>void f(Cont &v) {- auto temp = v.back(); v.pop_back(); // Do some work on temp std::cout << temp << std::endl;}
which is how I'd prefer to write this type of code.
Other Answers
Answered Dec 17, 2015 · 200 votes
Actually, usecase for template template parameters is rather obvious. Once you learn that C++ stdlib has gaping hole of not defining stream output operators for standard container types, you would proceed to write something like:
template<typename T>static inline std::ostream& operator<<(std::ostream& out, std::list<T> const& v){ out << '['; if (!v.empty()) { for (typename std::list<T>::const_iterator i = v.begin(); ;) { out << *i; if (++i == v.end()) break; out << ", "; } } out << ']'; return out;}
Then you'd figure out that code for vector is just the same, for forward_list is the same, actually, even for multitude of map types it's still just the same. Those template classes don't have anything in common except for meta-interface/protocol, and using template template parameter allows to capture the commonality in all of them. Before proceeding to write a template though, it's worth to check a reference to recall that sequence containers accept 2 template arguments - for value type and allocator. While allocator is defaulted, we still should account for its existence in our template operator<<:
template<template <typename, typename> class Container, class V, class A>std::ostream& operator<<(std::ostream& out, Container<V, A> const& v)...-
Voila, that will work automagically for all present and future sequence containers adhering to the standard protocol. To add maps to the mix, it would take a peek at reference to note that they accept 4 template params, so we'd need another version of the operator<< above with 4-arg template template param. We'd also see that std:pair tries to be rendered with 2-arg operator<< for sequence types we defined previously, so we would provide a specialization just for std::pair.
Btw, with C+11 which allows variadic templates (and thus should allow variadic template template args), it would be possible to have single operator<< to rule them all. For example:
#include <iostream>#include <vector>#include <deque>#include <list>template<typename T, template<class,class...> class C, class... Args>std::ostream& operator <<(std::ostream& os, const C<T,Args...>& objs){ os << __PRETTY_FUNCTION__ << '\n'; for (auto const& obj : objs) os << obj << ' '; return os;}int main(){ std::vector<float> vf { 1.1, 2.2, 3.3, 4.4 }; std::cout << vf << '\n'; std::list<char> lc { 'a', 'b', 'c', 'd' }; std::cout << lc << '\n'; std::deque<int> di { 1, 2, 3, 4 }; std::cout << di << '\n'; return 0;}
Output
std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = float, C = vector, Args = <std::__1::allocator<float>>]1.1 2.2 3.3 4.4 std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = char, C = list, Args = <std::__1::allocator<char>>]a b c d std::ostream &operator<<(std::ostream &, const C<T, Args...> &) [T = int, C = deque, Args = <std::__1::allocator<int>>]1 2 3 4
Other Answers
Answered Oct 18, 2008 · 78 votes
Here is a simple example taken from 'Modern C++ Design - Generic Programming and Design Patterns Applied' by Andrei Alexandrescu:
He uses a classes with template template parameters in order to implement the policy pattern:
// Library codetemplate <template <class> class CreationPolicy>class WidgetManager : public CreationPolicy<Widget>{ ...};
He explains: Typically, the host class already knows, or can easily deduce, the template argument of the policy class. In the example above, WidgetManager always manages objects of type Widget, so requiring the user to specify Widget again in the instantiation of CreationPolicy is redundant and potentially dangerous.In this case, library code can use template template parameters for specifying policies.
The effect is that the client code can use 'WidgetManager' in a more elegant way:
typedef WidgetManager<MyCreationPolicy> MyWidgetMgr;-
Instead of the more cumbersome, and error prone way that a definition lacking template template arguments would have required:
typedef WidgetManager< MyCreationPolicy<Widget> > MyWidgetMgr;-
2/5
Top Answer
Answered Aug 25, 2013 · 1 votes
Exception handling is the ability of a program to intercept run-time errors, take corrective measures, and then continue.
One common use for exception handling could be found when you are attempting to open a file. If a file does not exist it could potentially make the program unreliable. In order to circumvent that issue you need to utilize an Exception handler. Here is a method that opens a text file that I made for an old project.
public static void openFile() { JFileChooser getData = new JFileChooser(); if ( getData.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) { java.io.File dataSheet = getData.getSelectedFile(); try { input = new Scanner (dataSheet); } catch ( Exception e ) { GenerateInterface.theGame.printOutput( "File does not exist." ); } }}
As you can see if the file does not exist it catches (intercepts) the error, then it continues by running the code I wrote for that exception.
3/5
Top Answer
Answered Mar 17, 2014 · 7 votes
Probably one of the most interesting use cases I have seen would be Duff's Device the case where you extend a scope within a switch over multiple cases which would look something like this:
void send( int *to, const int *from, int count){ int n = (count + 7) / 8; switch(count % 8) { case 0: do { *to = *from++; // <- Scope start case 7: *to = *from++; case 6: *to = *from++; case 5: *to = *from++; case 4: *to = *from++; case 3: *to = *from++; case 2: *to = *from++; case 1: *to = *from++; } while(--n > 0); // <- Scope end }}
4/5
Top Answer
Answered Jun 20, 2020 · 6 votes
Inline assembly (and on a related note, calling external functions written purely in assembly) can be extremely useful or absolutely essential for reasons such as writing device drivers, direct access to hardware or processor capabilities not defined in the language, hardware-supported parallel processing (as opposed to multi-threading) such as CUDA, interfacing with FPGAs, performance, etc.
It is also important because some things are only possible by going "beneath" the level of abstraction provided by the Standard (both C++ and C).
The Standard(s) recognize that some things will be inherently implementation-defined, and allow for that throughout the Standard. One of these allowances (perhaps the lowest-level) is recognition of asm. Well, "sort of" recognition:
In C (N1256), it is found in the Standard under "Common extensions":
J.5.10 The asm keyword 1 The asm keyword may be used to insert assembly language directly into the translator output (6.8). The most common implementation is via a statement of the form:
asm ( character-string-literal );
In C++ (N3337), it has similar caveats:
§7.4/1 An asm declaration has the form
asm-definition:
asm ( string-literal ) ;
The asm declaration is conditionally-supported; its meaning is implementation-defined. [ Note: Typically it is used to pass information through the implementation to an assembler. —end note]
It should be noted that an important development in recent years is that attempting to increase performance by using inline assembly is often counter-productive, unless you know exactly what you are doing. Compiler/optimizer register usage decisions, awareness of pipeline and branch prediction behavior, etc., are almost always enough for most uses.
On the other hand, processors in recent years have added CPU-level support for higher-level operations (such as Intel's AES extensions) that can increase performance by several orders of magnitude for specialized applications.
So:
Legacy feature? Not at all. It is absolutely essential for some requirements.
Educational feature? In an ideal world, only if accompanied by a series of lectures explaining why you'll probably never need it, and if you ever do need it, how to limit it's visible surface area to the rest of your application as much as possible.
5/5
www.geeksforgeeks.org › storage-area-networksStorage Area Networks - GeeksforGeeks
www.geeksforgeeks.org › storage-area-networksSep 2, 2024 · A Storage Area Network (SAN) is a specialized network architecture that provides block-level storage access to servers and applications. SANs are typically used to provide high-speed, scalable storage for mission-critical applications, such as databases, email servers, and virtualized environments.
iboysoft.com › wiki › storage-area-networkWhat Is Storage Area Network? | SAN Examples | SAN VS NAS
iboysoft.com › wiki › storage-area-networkAug 27, 2024 · This post offers a brief introduction of Storage Area Network, the examples of SAN, the pros and cons of SAN and the differences between SAN and NAS.
www.sangfor.com › storage-area-networks-sanUnderstanding Storage Area Networks: A Comprehensive Guide
www.sangfor.com › storage-area-networks-sanAug 29, 2024 · What are some common use cases for Storage Area Networks? SANs are often used for storing databases, virtualization, backups, disaster recovery, and high-performance computing, requiring fast and reliable storage access.
climbtheladder.com › storage-area-network10 Storage Area Network Interview Questions and Answers
climbtheladder.com › storage-area-network3 days ago · A Storage Area Network (SAN) is a high-speed network providing block-level access to storage. Its basic components include: Hosts: Servers that utilize SAN storage for data processing. Switches: Connect SAN components, managing data traffic. Storage Devices: Disk arrays or tape libraries storing data.
www.auvik.com › franklyit › blog11 Types of Networks: Understanding the Differences - Auvik
www.auvik.com › franklyit › blogAug 19, 2024 · A storage area network (SAN), or network behind the servers, is a special purpose high-speed computer network that provides any-to-any access to storage. The main purpose of a SAN is to transfer data between different storage devices and between the computer network and storage devices.
www.hotbot.com › answers › what-is-storage-area-networkWhat is storage area network? - HotBot
www.hotbot.com › answers › what-is-storage-area-network6 days ago · Answer. A Storage Area Network (SAN) is a specialized, high-speed network that provides block-level network access to storage. SANs are typically used to enhance storage devices, such as disk arrays, tape libraries, and Optical Jukeboxes, making them accessible to multiple servers. Let's delve into the various facets of SANs and explore their ...
People also ask
What is a storage area network (SAN)?
- Storage Area Networks (SANs) transfer storage processing from servers to different networks. High availability, scalability, flexibility, and easier management are all made feasible by central and consolidated SANs. By using a remote copy, remote site data transfer and vaulting SANs shield data from malicious assaults and natural disasters.
Storage Area Networks - GeeksforGeeks
www.geeksforgeeks.org/storage-area-networks/What are some common storage area network interview questions?
- Here are 20 commonly asked Storage Area Network interview questions and answers to prepare you for your interview: 1. What is a Storage Area Network (SAN)? A Storage Area Network (SAN) is a network of storage devices that are connected together so that they can be accessed by computers and servers.
20 Storage Area Network Interview Questions and Answers
climbtheladder.com/storage-area-network-interview-questions/What is a storage area network?
- Storage area networks are primarily used to connect servers to storage devices including disk-based storage and tape libraries. Fibre Channel (FC): A Fibre Channel is one of the maximum broadly used SAN storage connections.
Storage Area Networks - GeeksforGeeks
www.geeksforgeeks.org/storage-area-networks/Do you need a storage area network?
- This is surprising given that almost every enterprise needs a storage solution in one form or another. From storing websites and servers to emails and SAN devices, storage area networks are essential for maintaining an enterprise-scale network.
Ultimate Guide with 10 Best Storage Area Networks Tools 2023 - ITPRC
www.itprc.com/ultimate-guide-to-storage-area-networks/www.itprc.com › ultimate-guide-to-storage-areaUltimate Guide to Storage Area Networks (SANs) - ITPRC
www.itprc.com › ultimate-guide-to-storage-areaAug 16, 2024 · In this article, we talk you through how storage area networks work and break down some of the best SAN tools on the market. What is a Storage Area Network? Storage Area Networks (commonly referred to as SANs) are a scalable network and block-level storage method.
Searches related to what are some uses of a storage area network example worksheet